結果

問題 No.2709 1975 Powers
ユーザー ryota2357ryota2357
提出日時 2024-03-31 01:29:08
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 1,341 bytes
コンパイル時間 1,066 ms
コンパイル使用メモリ 121,188 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 01:29:13
合計ジャッジ時間 4,055 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 119 ms
6,676 KB
testcase_04 AC 197 ms
6,676 KB
testcase_05 AC 133 ms
6,676 KB
testcase_06 AC 43 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 39 ms
6,676 KB
testcase_09 AC 134 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 5 ms
6,676 KB
testcase_12 AC 12 ms
6,676 KB
testcase_13 AC 140 ms
6,676 KB
testcase_14 AC 21 ms
6,676 KB
testcase_15 AC 24 ms
6,676 KB
testcase_16 AC 106 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 14 ms
6,676 KB
testcase_19 AC 195 ms
6,676 KB
testcase_20 AC 3 ms
6,676 KB
testcase_21 AC 38 ms
6,676 KB
testcase_22 AC 232 ms
6,676 KB
testcase_23 AC 232 ms
6,676 KB
testcase_24 AC 232 ms
6,676 KB
testcase_25 AC 233 ms
6,676 KB
testcase_26 AC 232 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

long long pow_mod(long long x, long long n, long long mod) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) {
            ret *= x;
            ret %= mod;
        }
        x *= x;
        x %= mod;
        n >>= 1;
    }
    return ret;
}

int main() {
    int n, p, q;
    cin >> n >> p >> q;
    assert(4 <= n && n <= 200);
    assert(2 <= q && q < p && p <= 100000);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) { cin >> a[i]; }
    for (int i = 0; i < n; ++i) { assert(1 <= a[i] && a[i] <= 2000000); }
    sort(a.begin(), a.end());

    vector<int> m10(n), m9(n), m7(n), m5(n);
    for (int i = 0; i < n; ++i) {
        m10[i] = pow_mod(10, a[i], p);
        m9[i] = pow_mod(9, a[i], p);
        m7[i] = pow_mod(7, a[i], p);
        m5[i] = pow_mod(5, a[i], p);
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            for (int k = j + 1; k < n; ++k) {
                for (int l = k + 1; l < n; ++l) {
                    long long sum = m10[i] + m9[j] + m7[k] + m5[l];
                    if (sum % p == q) {
                        ans += 1;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0