結果

問題 No.2264 Gear Coloring
ユーザー SSRSSSRS
提出日時 2023-04-07 21:55:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 1,261 bytes
コンパイル時間 2,300 ms
コンパイル使用メモリ 205,360 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 17:00:15
合計ジャッジ時間 3,316 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 8 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 8 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 98 ms
6,944 KB
testcase_15 AC 8 ms
6,944 KB
testcase_16 AC 103 ms
6,940 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 6 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long modpow(long long a, long long b){
	long long ans = 1;
	while (b > 0){
		if (b % 2 == 1){
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		b /= 2;
	}
	return ans;
}
long long modinv(long long a){
	return modpow(a, MOD - 2);
}
int main(){
  int N;
  long long M;
  cin >> N >> M;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  int L = 1;
  for (int i = 0; i < N; i++){
    L = lcm(L, A[i]);
  }
  vector<int> F;
  for (int i = 1; i * i <= L; i++){
    if (L % i == 0){
      F.push_back(i);
      if (i * i < L){
        F.push_back(L / i);
      }
    }
  }
  sort(F.begin(), F.end());
  int cnt = F.size();
  vector<int> C1(cnt, 0);
  for (int i = cnt - 1; i >= 0; i--){
    C1[i] = L / F[i];
    for (int j = i + 1; j < cnt; j++){
      if (F[j] % F[i] == 0){
        C1[i] -= C1[j];
      }
    }
  }
  vector<long long> C2(cnt, 1);
  for (int i = 0; i < cnt; i++){
    for (int j = 0; j < N; j++){
      C2[i] *= modpow(M, gcd(A[j], F[i]));
      C2[i] %= MOD;
    }
  }
  long long ans = 0;
  for (int i = 0; i < cnt; i++){
    ans += C1[i] * C2[i];
    ans %= MOD;
  }
  ans *= modinv(L);
  ans %= MOD;
  cout << ans << endl;
}
0