結果

問題 No.2709 1975 Powers
ユーザー rikeichan
提出日時 2024-03-31 18:22:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 875 bytes
コンパイル時間 1,865 ms
コンパイル使用メモリ 171,112 KB
実行使用メモリ 13,764 KB
最終ジャッジ日時 2024-09-30 21:15:14
合計ジャッジ時間 5,473 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 1 TLE * 1 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;


int modpow(long long x, long long A, long long mod){
    long long res=1;
    while (A > 0){
        if (A&1) res = res * x % mod;
        x = x * x % mod;
        A >>= 1;
    }
    return res;
}

int main(){
    long long N, P, Q;
    cin >> N >> P >> Q;
    long long A[N];
    for (int i=0; i<N; ++i){
        cin >> A[i];
    }

    sort(A, A+N);
    int ans=0;
    for (int i=0; i<N-3; ++i){
        long long a = modpow(10, A[i], P);
        for (int j=i+1; j<N-2; ++j){
            long long b = modpow(9, A[j], P);
            for (int k=j+1; k<N-1; ++k){
                long long c = modpow(7, A[k], P);
                for (int l=k+1; l<N; ++l){
                    long long d = modpow(5, A[l], P);
                    if ((a+b+c+d)%P==Q){ans++;}
                }
            }
        }
    }
    cout << ans;
}
0