結果

問題 No.2709 1975 Powers
ユーザー ryota2357ryota2357
提出日時 2024-03-31 01:22:51
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,295 bytes
コンパイル時間 1,069 ms
コンパイル使用メモリ 120,776 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 01:22:58
合計ジャッジ時間 6,170 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 120 ms
6,676 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

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());

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