P1820 尋找AP數
阿新 • • 發佈:2019-01-26
素數 使用 反素數 main primes prim mes art txt
P1820 尋找AP數
這道題跟那個反素數挺像的,於是就使用了經典的打表。
打表程序:
#include<bits/stdc++.h> using std::cin; using std::cout; using std::endl; #define ll long long const int primes[] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29};// 10 const ll limit = 1500000000; const ll INF = 0x3f3f3f3f3f3f3f3f; ll maxv = -INF; int ysgs(int x) { int ans = 1; for(int i = 1; i <= 10; i++) { int cnt = 0; while(x % primes[i] == 0) { cnt++; x /= primes[i]; } ans = ans * (cnt + 1); } return ans; } int main() { freopen("out.txt", "w", stdout); printf("const int chart[] = {"); for(int i = 1; i <= limit; i++) { ll temp = ysgs(i); if(temp > maxv) { printf("%d, ", i); } maxv = std::max(maxv, temp); } printf("};\n"); return 0; }
提交的程序:
#include<bits/stdc++.h> using std::cin; using std::cout; using std::endl; #define ll long long const int chart[68] = {1, 2, 4, 6, 12, 24, 36, 48, 60, 120, 180, 240, 360, 720, 840, 1260, 1680, 2520, 5040, 7560, 10080, 15120, 20160, 25200, 27720, 45360, 50400, 55440, 83160, 110880, 166320, 221760, 277200, 332640, 498960, 554400, 665280, 720720, 1081080, 1441440, 2162160, 2882880, 3603600, 4324320, 6486480, 7207200, 8648640, 10810800, 14414400, 17297280, 21621600, 32432400, 36756720, 43243200, 61261200, 73513440, 110270160, 122522400, 147026880, 183783600, 245044800, 294053760, 367567200, 551350800, 698377680, 735134400, 1102701600, 1396755360}; int main() { ll n; while(cin >> n) { int idx = std::lower_bound(chart, chart + 68, n) - chart; if(chart[idx] > n) idx--; cout << chart[idx] << endl; } return 0; }
P1820 尋找AP數