結果
問題 | No.1532 Different Products |
ユーザー | tatyam |
提出日時 | 2021-05-17 15:03:28 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,611 bytes |
コンパイル時間 | 3,915 ms |
コンパイル使用メモリ | 233,472 KB |
実行使用メモリ | 36,388 KB |
最終ジャッジ日時 | 2024-11-15 01:07:19 |
合計ジャッジ時間 | 78,614 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
36,012 KB |
testcase_01 | AC | 859 ms
36,112 KB |
testcase_02 | AC | 99 ms
35,984 KB |
testcase_03 | AC | 40 ms
35,972 KB |
testcase_04 | AC | 60 ms
36,088 KB |
testcase_05 | AC | 24 ms
35,984 KB |
testcase_06 | AC | 147 ms
36,108 KB |
testcase_07 | AC | 241 ms
36,052 KB |
testcase_08 | AC | 272 ms
36,028 KB |
testcase_09 | AC | 428 ms
35,984 KB |
testcase_10 | AC | 764 ms
36,080 KB |
testcase_11 | AC | 692 ms
36,012 KB |
testcase_12 | AC | 1,108 ms
36,388 KB |
testcase_13 | AC | 704 ms
36,212 KB |
testcase_14 | AC | 1,595 ms
36,096 KB |
testcase_15 | AC | 241 ms
36,012 KB |
testcase_16 | AC | 1,181 ms
36,148 KB |
testcase_17 | AC | 636 ms
36,032 KB |
testcase_18 | AC | 512 ms
36,052 KB |
testcase_19 | AC | 1,022 ms
36,268 KB |
testcase_20 | AC | 1,542 ms
36,056 KB |
testcase_21 | AC | 1,292 ms
36,080 KB |
testcase_22 | AC | 808 ms
36,280 KB |
testcase_23 | AC | 541 ms
36,220 KB |
testcase_24 | AC | 1,465 ms
36,220 KB |
testcase_25 | AC | 1,187 ms
36,180 KB |
testcase_26 | AC | 550 ms
35,996 KB |
testcase_27 | AC | 1,417 ms
35,992 KB |
testcase_28 | AC | 1,105 ms
36,164 KB |
testcase_29 | AC | 1,505 ms
36,140 KB |
testcase_30 | AC | 1,579 ms
36,156 KB |
testcase_31 | AC | 1,562 ms
36,028 KB |
testcase_32 | AC | 1,649 ms
36,036 KB |
testcase_33 | AC | 1,474 ms
35,992 KB |
testcase_34 | AC | 1,527 ms
36,192 KB |
testcase_35 | AC | 1,562 ms
36,116 KB |
testcase_36 | AC | 1,638 ms
36,080 KB |
testcase_37 | AC | 1,496 ms
36,084 KB |
testcase_38 | AC | 1,540 ms
36,216 KB |
testcase_39 | AC | 1,528 ms
36,228 KB |
testcase_40 | AC | 1,509 ms
36,048 KB |
testcase_41 | AC | 1,597 ms
36,052 KB |
testcase_42 | AC | 1,587 ms
36,180 KB |
testcase_43 | AC | 1,559 ms
36,124 KB |
testcase_44 | AC | 1,659 ms
36,080 KB |
testcase_45 | AC | 1,622 ms
36,092 KB |
testcase_46 | AC | 1,623 ms
36,056 KB |
testcase_47 | AC | 1,641 ms
36,124 KB |
testcase_48 | AC | 1,652 ms
36,220 KB |
testcase_49 | AC | 1,653 ms
36,256 KB |
testcase_50 | AC | 1,686 ms
36,172 KB |
testcase_51 | AC | 1,608 ms
36,104 KB |
testcase_52 | AC | 1,650 ms
36,036 KB |
testcase_53 | AC | 1,657 ms
36,168 KB |
testcase_54 | AC | 1,661 ms
36,100 KB |
testcase_55 | AC | 1,629 ms
36,120 KB |
testcase_56 | AC | 1,614 ms
36,168 KB |
testcase_57 | AC | 1,596 ms
36,060 KB |
testcase_58 | AC | 1,618 ms
36,172 KB |
testcase_59 | AC | 1,625 ms
36,032 KB |
testcase_60 | AC | 1,631 ms
36,188 KB |
testcase_61 | AC | 2 ms
6,816 KB |
testcase_62 | AC | 14 ms
35,944 KB |
testcase_63 | WA | - |
ソースコード
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; using u32 = uint32_t; using u64 = uint64_t; vector<bool> sieve_of_atkin(int N){ vector<bool> isprime(N + 1); const int sqrtN = sqrt(N); int n; for(int z = 1; z <= 5; z += 4) for(int y = z; y <= sqrtN; y += 6){ for(int x = 1; x <= sqrtN && (n = 4*x*x+y*y) <= N; ++x) isprime[n] = !isprime[n]; for(int x = y+1; x <= sqrtN && (n = 3*x*x-y*y) <= N; x += 2) isprime[n] = !isprime[n]; } for(int z = 2; z <= 4; z += 2) for(int y = z; y <= sqrtN; y += 6){ for(int x = 1; x <= sqrtN && (n = 3*x*x+y*y) <= N; x += 2) isprime[n] = !isprime[n]; for(int x = y+1; x <= sqrtN && (n = 3*x*x-y*y) <= N; x += 2) isprime[n] = !isprime[n]; } for(int y = 3; y <= sqrtN; y += 6) for(int z = 1; z <= 2; ++z){ for(int x = z; x <= sqrtN && (n = 4*x*x+y*y) <= N; x += 3) isprime[n] = !isprime[n]; } for(int n = 5; n <= sqrtN; ++n) if(isprime[n]) for(int k = n*n; k <= N; k+=n*n) isprime[k] = false; isprime[2] = isprime[3] = true; return isprime; } vector<u32> primes(int N){ auto isprime = sieve_of_atkin(N); vector<u32> ans; for(int i = 2; i <= N; i++) if(isprime[i]) ans.push_back(i); return ans; } int main(){ constexpr u32 MAX = 1 << 22; u32 N; u64 K; cin >> N >> K; if(K == 1) return puts("1") & 0; const vector<u32> P = primes(N); vector<u32> lg(N + 1); for(u32 i : P) lg[i] = round(logl(i) / logl(K) * MAX); for(u32 p : P) for(u32 i = 2; i * p <= N; i++) lg[i * p] = lg[i] + lg[p]; vector<u64> dp(MAX + 1); dp[0] = 2; for(u32 i = 2; i <= N; i++){ const u32 x = lg[i]; for(u32 i = MAX; i >= x; i--) dp[i] += dp[i - x]; } dp.resize(MAX - 7); u64 ans = accumulate(dp.begin(), dp.end(), -1LL); auto solve = [N](u64 x) -> u32 { vector<pair<u64, u32>> dp = {{1, 2}}; for(u32 j = 2; j <= N; j++) if(x % j == 0){ auto update = [x, j](pair<u64, u32>& a){ a.first *= j; if(a.first < x && x % a.first) a.first = 0; }; vector<pair<u64, u32>> dp2; u32 p = 0, q = 0; while(q < dp.size()){ if(dp[q].first == 0){ q++; continue; } if(p < dp.size()){ if(p == q || dp[p].first < dp[q].first){ dp2.push_back(dp[p]); update(dp[p]); p++; } else if(dp[p].first == dp[q].first){ dp2.emplace_back(dp[p].first, dp[p].second + dp[q].second); update(dp[p]); p++; q++; } else{ dp2.push_back(dp[q]); q++; } continue; } if(dp[q].first > x) break; dp2.push_back(dp[q]); q++; } swap(dp, dp2); } if(dp.back().first != x) return 0; return dp.back().second; }; for(u64 i = max<int64_t>(2, K - 1e6); i <= K; i++){ u64 x = i; u32 y = 0; for(u32 p : P) while(x % p == 0){ x /= p; y += lg[p]; } if(y >= dp.size()) ans += solve(i); } cout << ans << endl; }