結果

問題 No.2264 Gear Coloring
ユーザー karinohitokarinohito
提出日時 2023-03-10 15:27:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 918 bytes
コンパイル時間 2,855 ms
コンパイル使用メモリ 218,092 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 06:44:19
合計ジャッジ時間 4,036 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define rep(i, n) for (int i=0;i<n;i++)

const ll mod=998244353;
ll modPow(ll a,ll n,ll p=mod) {
    ll res=1,k=a%mod;
    while(n){
        if(n%2==1)res=(res*k)%p;
        k=(k*k)%p;
        n/=2;
    }
    return res;
}

int main() {
    ll N,M,L=1,an=0;
    cin>>N>>M;
    vll A(N),P;
    rep(i,N){
	    cin>>A[i];
    	L=L/gcd(L,A[i])*A[i];
    }
    for(ll i=1;i*i<=L;i++)if(L%i==0){
        P.push_back(i);
        if(L!=i*i)P.push_back(L/i);
    }
    sort(P.begin(),P.end());
    ll n=P.size();
    vll R(n,1);
    unordered_map<ll,ll> powMg;

    rep(j,n)powMg[P[j]]=modPow(M,P[j]);
    rep(j,n)rep(i,N)R[j]=(R[j]*powMg[gcd(A[N-1-i],P[j])])%mod;
    rep(i,n)rep(j,i){
        if(P[i]%P[j]==0)R[i]-=R[j];
        R[i]%=mod;
    }

    rep(i,n)an=(an+(R[i]*modPow(P[i],mod-2))%mod)%mod;
    cout<<(an+mod)%mod<<endl;
}
0