結果
| 問題 | No.2709 1975 Powers | 
| コンテスト | |
| ユーザー |  hatsuka_iwa | 
| 提出日時 | 2024-03-31 15:33:03 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 287 ms / 2,000 ms | 
| コード長 | 855 bytes | 
| コンパイル時間 | 1,833 ms | 
| コンパイル使用メモリ | 203,844 KB | 
| 最終ジャッジ日時 | 2025-02-20 17:57:49 | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 25 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, P, Q, C = 0; cin >> N >> P >> Q;
  vector<int> A(N); for (int &a : A) cin >> a; 
  vector B(4, vector<int>(N));
  sort(A.begin(), A.end());
  auto pow = [&](long long x, long long n) {
    long long ret = 1;
    while (n) {
      if (n & 1) ret = ret * x % P;
      x = x * x % P;
      n = n >> 1;
    }
    return ret;
  };
  for (int i = 0; i < N; i++) {
    B.at(0).at(i) = pow(10, A.at(i));
    B.at(1).at(i) = pow(9, A.at(i));
    B.at(2).at(i) = pow(7, A.at(i));
    B.at(3).at(i) = pow(5, A.at(i));
  }
  for (int i = 0; i < N - 3; i++)
    for (int j = i + 1; j < N - 2; j++)
      for (int k = j + 1; k < N - 1; k++)
        for (int l = k + 1; l < N; l++)
          if ((B.at(0).at(i) + B.at(1).at(j) + B.at(2).at(k) + B.at(3).at(l)) % P == Q) C++;
  cout << C << endl;
}
            
            
            
        