結果
問題 | No.2849 Birthday Donuts |
ユーザー | 👑 AngrySadEight |
提出日時 | 2024-06-20 00:24:54 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,244 ms / 6,000 ms |
コード長 | 2,295 bytes |
コンパイル時間 | 935 ms |
コンパイル使用メモリ | 80,180 KB |
実行使用メモリ | 10,368 KB |
最終ジャッジ日時 | 2024-07-01 01:46:25 |
合計ジャッジ時間 | 45,223 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
10,340 KB |
testcase_01 | AC | 42 ms
10,244 KB |
testcase_02 | AC | 2,170 ms
10,192 KB |
testcase_03 | AC | 2,176 ms
10,368 KB |
testcase_04 | AC | 2,244 ms
10,368 KB |
testcase_05 | AC | 2,225 ms
10,240 KB |
testcase_06 | AC | 2,220 ms
10,228 KB |
testcase_07 | AC | 2,228 ms
10,240 KB |
testcase_08 | AC | 2,217 ms
10,216 KB |
testcase_09 | AC | 2,222 ms
10,240 KB |
testcase_10 | AC | 2,221 ms
10,240 KB |
testcase_11 | AC | 2,232 ms
10,276 KB |
testcase_12 | AC | 2,030 ms
10,304 KB |
testcase_13 | AC | 2,097 ms
10,240 KB |
testcase_14 | AC | 2,138 ms
10,240 KB |
testcase_15 | AC | 2,089 ms
10,240 KB |
testcase_16 | AC | 2,190 ms
10,240 KB |
testcase_17 | AC | 2,029 ms
10,260 KB |
testcase_18 | AC | 2,173 ms
10,368 KB |
testcase_19 | AC | 2,078 ms
10,240 KB |
testcase_20 | AC | 2,092 ms
10,192 KB |
testcase_21 | AC | 1,246 ms
10,240 KB |
ソースコード
#include <cassert> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; using ll = long long; ll my_gcd(ll a, ll b) { ll ret = 0; if (a < b) { swap(a, b); } if (b == 0) { ret = a; } else { ret = my_gcd(b, a % b); } return ret; } int main() { vector<ll> divisor(300002, -1); for (ll i = 2; i <= 300000; i++) { for (ll j = 2; j * i <= 300000; j++) { divisor[j * i] = j; } } vector<ll> phi(300002, 0); for (ll i = 2; i <= 300000; i++) { ll now = i; ll div = -1; ll tot = i; while (true) { if (divisor[now] == -1) { if (now != div) { tot = tot * (now - 1); tot /= now; } break; } if (div != divisor[now]) { div = divisor[now]; tot = tot * (div - 1); tot /= div; } now /= div; } phi[i] = tot; } vector<ll> phi_sum(300002, 0); for (ll i = 2; i <= 300000; i++) { phi_sum[i] = phi_sum[i - 1] + phi[i]; } ll T; cin >> T; ll prev_ans = 0; while (T--) { ll L, R; cin >> L >> R; L = (prev_ans ^ L); R = (prev_ans ^ R); assert(L <= R); assert(L >= 2); assert(R <= 200000); ll ans = 0; for (ll i = 2; i <= 500; i++) { ll k1 = (L - 1) / i; ll k2 = R / i; if (k1 < k2) { ans += phi[i]; } } ll left = 0; ll right = 1; ll prev = R; while (true) { if (R < 500) { break; } ll nl = (L - 1) / (left + 1); ll nr = R / (right + 1); ll val = max(nl, nr); if (left != right) { ans += (phi_sum[prev] - phi_sum[max(val, 500LL)]); } if (val <= 500) { break; } prev = val; if (nl >= nr) { left++; } else { right++; } } cout << ans << endl; prev_ans = ans; } }