結果

問題 No.3153 probability max K
ユーザー daiota
提出日時 2025-05-21 02:07:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 838 bytes
コンパイル時間 1,732 ms
コンパイル使用メモリ 162,564 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-21 02:07:39
合計ジャッジ時間 6,216 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i=0;i<ll(n);i++)




const ll  MOD=998244353;
ll f(ll x,ll n){
    ll res=1;
    while(n!=0LL){
	if(n%2!=0LL) res=(res*x)%MOD;
	x=(x*x)%MOD;
	n/=2;
   }
    return res;
}


ll gcd(ll a,ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}





int main(void){
	cin.tie(nullptr);  ios_base::sync_with_stdio(false);
	ll i,j;



	ll N,K;
	cin >> N >> K;


	vector<ll> a(N+1);
	for(i=1;i<=N;i++){
		cin >> a[i];
	}


	ll x=1,y=1;
	for(i=1;i<=N;i++){

		ll p=min(a[i],K);
		ll e=gcd(a[i],p);
		p/=e;
		ll q=a[i]/e;

		q=f(q,MOD-2);
		x*=(p*q)%MOD;
		x%=MOD;


		p=min(a[i],K-1);
		e=gcd(a[i],p);
		p/=e;
		q=a[i]/e;

		q=f(q,MOD-2);
		y*=(p*q)%MOD;
		y%=MOD;


	}



	cout << (x-y+MOD)%MOD << endl;









	return 0;

}




0