結果
問題 | No.1261 数字集め |
ユーザー | magsta |
提出日時 | 2020-10-08 22:42:12 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,388 bytes |
コンパイル時間 | 1,139 ms |
コンパイル使用メモリ | 78,392 KB |
実行使用メモリ | 35,856 KB |
最終ジャッジ日時 | 2024-07-21 03:43:01 |
合計ジャッジ時間 | 34,344 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,140 ms
35,712 KB |
testcase_01 | AC | 115 ms
14,592 KB |
testcase_02 | AC | 241 ms
26,752 KB |
testcase_03 | AC | 244 ms
27,008 KB |
testcase_04 | AC | 157 ms
18,688 KB |
testcase_05 | AC | 313 ms
34,304 KB |
testcase_06 | AC | 179 ms
20,736 KB |
testcase_07 | AC | 245 ms
27,776 KB |
testcase_08 | AC | 141 ms
17,152 KB |
testcase_09 | AC | 181 ms
21,504 KB |
testcase_10 | AC | 11 ms
5,376 KB |
testcase_11 | AC | 317 ms
34,048 KB |
testcase_12 | AC | 282 ms
30,720 KB |
testcase_13 | AC | 256 ms
28,124 KB |
testcase_14 | AC | 31 ms
6,144 KB |
testcase_15 | AC | 129 ms
15,616 KB |
testcase_16 | AC | 272 ms
27,904 KB |
testcase_17 | AC | 203 ms
23,168 KB |
testcase_18 | AC | 130 ms
15,956 KB |
testcase_19 | AC | 238 ms
27,136 KB |
testcase_20 | AC | 38 ms
6,784 KB |
testcase_21 | AC | 322 ms
35,712 KB |
testcase_22 | AC | 331 ms
35,632 KB |
testcase_23 | AC | 320 ms
35,712 KB |
testcase_24 | AC | 330 ms
35,716 KB |
testcase_25 | AC | 326 ms
35,708 KB |
testcase_26 | AC | 323 ms
35,712 KB |
testcase_27 | AC | 324 ms
35,752 KB |
testcase_28 | AC | 323 ms
35,712 KB |
testcase_29 | AC | 324 ms
35,712 KB |
testcase_30 | AC | 324 ms
35,776 KB |
testcase_31 | AC | 323 ms
35,840 KB |
testcase_32 | AC | 321 ms
35,840 KB |
testcase_33 | AC | 326 ms
35,716 KB |
testcase_34 | AC | 330 ms
35,700 KB |
testcase_35 | AC | 323 ms
35,712 KB |
testcase_36 | AC | 324 ms
35,712 KB |
testcase_37 | AC | 326 ms
35,648 KB |
testcase_38 | AC | 324 ms
35,772 KB |
testcase_39 | AC | 322 ms
35,712 KB |
testcase_40 | AC | 324 ms
35,656 KB |
testcase_41 | AC | 327 ms
35,712 KB |
testcase_42 | AC | 321 ms
35,820 KB |
testcase_43 | AC | 325 ms
35,688 KB |
testcase_44 | AC | 340 ms
31,744 KB |
testcase_45 | WA | - |
testcase_46 | AC | 158 ms
19,072 KB |
testcase_47 | WA | - |
testcase_48 | AC | 258 ms
27,392 KB |
testcase_49 | AC | 304 ms
31,616 KB |
testcase_50 | WA | - |
testcase_51 | AC | 86 ms
10,744 KB |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | AC | 264 ms
26,240 KB |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | WA | - |
testcase_63 | AC | 58 ms
8,064 KB |
testcase_64 | WA | - |
testcase_65 | WA | - |
testcase_66 | AC | 187 ms
20,736 KB |
testcase_67 | AC | 269 ms
29,696 KB |
testcase_68 | WA | - |
testcase_69 | AC | 168 ms
19,552 KB |
testcase_70 | WA | - |
testcase_71 | WA | - |
testcase_72 | WA | - |
testcase_73 | WA | - |
testcase_74 | WA | - |
testcase_75 | WA | - |
testcase_76 | AC | 261 ms
26,240 KB |
testcase_77 | AC | 298 ms
29,944 KB |
testcase_78 | WA | - |
testcase_79 | AC | 296 ms
30,892 KB |
testcase_80 | WA | - |
testcase_81 | WA | - |
testcase_82 | WA | - |
testcase_83 | WA | - |
testcase_84 | WA | - |
testcase_85 | WA | - |
testcase_86 | WA | - |
testcase_87 | WA | - |
testcase_88 | WA | - |
testcase_89 | WA | - |
testcase_90 | WA | - |
testcase_91 | WA | - |
testcase_92 | WA | - |
testcase_93 | WA | - |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <utility> #define MOD 1000000007 using namespace std; long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } long long modinv(long long a) { return modpow(a, MOD - 2); } vector<long long> enum_divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); // 重複しないならば i の相方である N/i も push if (N/i != i) res.push_back(N/i); } } // 小さい順に並び替える sort(res.begin(), res.end()); return res; } long long p_q_r(long long p, long long q, long long r, long long M){ if (r > p) swap(p, r); if (q > p) swap(p, q); if (r > q) swap(q, r); long long a, b, c, d, e; a = modpow(p, M - 2); b = modpow(q, M - 2); c = modpow(r, M - 2); d = (((a - c) * modinv(p - r) % MOD) + MOD) % MOD; e = (((b - c) * modinv(q - r) % MOD) + MOD) % MOD; d = d * p % MOD; e = e * q % MOD; return (((d - e) * modinv(p - q) % MOD) + MOD) % MOD; } int main() { long long N, M; cin >> N >> M; long long A[N]; for (int i = 1; i < N; i++) cin >> A[i]; const auto &res = enum_divisors(N); long long count = 0; long long ans = 0; for (int i = 0; i < res.size(); i++){ for (int j = 0; j < res.size(); j++){ if (res[i] == 1 || res[j] == 1) continue; if (N == (res[i] * res[j])) continue; if (N % (res[i] * res[j]) == 0){ long long p = A[res[i] - 1] - 1; long long q = A[res[i] * res[j] - 1] - 1; long long r = A[N - 1] - 1; ans = (ans + p_q_r(p, q, r, M)) % MOD; } } } cout << ans << endl; long long Q; cin >> Q; vector<long long> num[N]; bool flag[N]; for (int i = 0; i < N; i++) flag[i] = false; for (int i = 0; i < Q; i++){ long long X, Y; cin >> X >> Y; if (Y == N){ const auto &res_ = enum_divisors(X); for (int i = 0; i < res_.size(); i++){ if (res_[i] == 1 || res_[i] == X) continue; long long p = A[res_[i] - 1] - 1; long long q = A[X - 1] - 1; long long r = A[Y - 1] - 1; ans = (ans + p_q_r(p, q, r, M)) % MOD; } for (int i = 0; i < num[X - 1].size(); i++){ long long p = A[num[X - 1][i] - 1] - 1; long long q = A[X - 1] - 1; long long r = A[Y - 1] - 1; ans = (ans + p_q_r(p, q, r, M)) % MOD; } flag[X - 1] = true; } if (Y != N){ if (N % Y == 0){ long long p = A[X - 1] - 1; long long q = A[Y - 1] - 1; long long r = A[N - 1] - 1; ans = (ans + p_q_r(p, q, r, M)) % MOD; } if (flag[Y - 1] == true){ long long p = A[X - 1] - 1; long long q = A[Y - 1] - 1; long long r = A[N - 1] - 1; ans = (ans + p_q_r(p, q, r, M)) % MOD; } } cout << ans << endl; } }