結果

問題 No.2709 1975 Powers
ユーザー takumi152
提出日時 2024-03-31 14:23:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 683 ms / 2,000 ms
コード長 1,218 bytes
コンパイル時間 1,271 ms
コンパイル使用メモリ 101,472 KB
最終ジャッジ日時 2025-02-20 17:12:08
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 998244353;

ll modpow(ll a, ll b, ll m = mod) {
  ll r = 1;
  while (b > 0) {
    if (b & 1) r = (r * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return r;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, p, q;
  cin >> n >> p >> q;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;

  sort(a.begin(), a.end());

  vector<ll> pow10mod(n), pow9mod(n), pow7mod(n), pow5mod(n);
  for (int i = 0; i < n; i++) {
    pow10mod[i] = modpow(10, a[i], p);
    pow9mod[i] = modpow(9, a[i], p);
    pow7mod[i] = modpow(7, a[i], p);
    pow5mod[i] = modpow(5, a[i], p);
  }

  ll 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++) {
          ll val = (pow10mod[i] + pow9mod[j] + pow7mod[k] + pow5mod[l]) % p;
          if (val == q) ans++;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}
0