結果
問題 |
No.2709 1975 Powers
|
ユーザー |
![]() |
提出日時 | 2024-03-31 14:06:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,675 ms / 2,000 ms |
コード長 | 1,289 bytes |
コンパイル時間 | 4,818 ms |
コンパイル使用メモリ | 259,472 KB |
最終ジャッジ日時 | 2025-02-20 16:55:37 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; using ll = long long; ll mod_pow(ll n, ll k, ll m) { ll res = 1; while (k > 0) { if (k & 1) { res = res * n % m; } n = n * n % m; k >>= 1; } return res; } int main() { ll N, P, Q; cin >> N >> P >> Q; vector<ll> A(N); for (ll i = 0; i < N; i++) { cin >> A[i]; } sort(A.begin(), A.end()); map<ll, vector<ll>> mp; for (auto a: A) { ll r = mod_pow(5, a, P); mp[r].push_back(a); } for (auto& [k, v]: mp) { sort(v.begin(), v.end()); } ll ans = 0; for (ll i = 0; i < N; i++) { for (ll j = i + 1; j < N; j++) { for (ll k = j + 1; k < N; k++) { ll s = (mod_pow(10, A[i], P) + mod_pow(9, A[j], P) + mod_pow(7, A[k], P)) % P; ll t = (Q - s + P) % P; if (mp.find(t) == mp.end()) { continue; } auto& v = mp[t]; auto it = lower_bound(v.begin(), v.end(), A[k] + 1); ans += v.end() - it; } } } cout << ans << endl; return 0; }