Submission #66473
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | #include<bits/stdc++.h> using namespace std; template < class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true ); } template < class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true ); } typedef long long ll; typedef vector< int > vint; typedef pair< int , int > pint; typedef vector< long long > vlong; typedef vector<string> vstring; #define _GLIBCXX_DEBUG #define vpush(a,x) a.push_back(x); #define rep(i, n) REP(i, 0, n) #define all(v) v.begin(), v.end() #define REP(i, x, n) for(int i = x; i < n; i++) const int INF = 1 << 30; const int dx[] = {1,0,-1,0,1,1,-1,-1}; const int dy[] = {0,-1,0,1,1,-1,-1,1}; #define stp(x) setprecision(x) ll MOD=998244353; vlong fact,fact_inv,inv; /* init_nCk :二項係数のための前処理 計算量:O(n) */ void init_nCk( int SIZE) { fact.resize(SIZE + 5); fact_inv.resize(SIZE + 5); inv.resize(SIZE + 5); fact[0] = fact[1] = 1; fact_inv[0] = fact_inv[1] = 1; inv[1] = 1; for ( int i = 2; i < SIZE + 5; i++) { fact[i] = fact[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD; } } /* nCk :MODでの二項係数を求める(前処理 int_nCk が必要) 計算量:O(1) */ long long nCk( int n, int k) { assert (!(n < k)); assert (!(n < 0 || k < 0)); return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD; } int main(){ cin.tie(nullptr); ios::sync_with_stdio( false ); ll n,k; cin>>n>>k; vlong a(n); rep(i,n){ cin>>a[i]; } ll cnt=0; rep(i,n){ if (gcd(k,a[i])==1){ cnt++; } } ll ans=0; init_nCk(cnt+10); REP(i,1,cnt+1){ ans+=nCk(cnt,i); ans%=MOD; } //cout<<cnt<<'\n'; cout<<ans<< '\n' ; return (0); } |
ステータス
項目 | データ |
---|---|
問題 | 1409 - Prime Combination |
ユーザー名 | ei1918 |
投稿日時 | 2021-05-06 12:13:06 |
言語 | C++17 |
状態 | Accepted |
得点 | 300 |
ソースコード長 | 1862 Byte |
最大実行時間 | 158 ms |
最大メモリ使用量 | 6896 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 300 / 300 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.txt | AC | 112 ms | 3420 KB |
1
|
in02.txt | AC | 132 ms | 3440 KB |
1
|
in03.txt | AC | 93 ms | 3012 KB |
1
|
in04.txt | AC | 49 ms | 1684 KB |
1
|
in05.txt | AC | 50 ms | 2028 KB |
1
|
in06.txt | AC | 130 ms | 4684 KB |
1
|
in07.txt | AC | 136 ms | 5304 KB |
1
|
in08.txt | AC | 135 ms | 4156 KB |
1
|
in09.txt | AC | 126 ms | 4624 KB |
1
|
in10.txt | AC | 134 ms | 5820 KB |
1
|
in11.txt | AC | 150 ms | 6836 KB |
1
|
in12.txt | AC | 136 ms | 6672 KB |
1
|
in13.txt | AC | 91 ms | 6896 KB |
1
|
in14.txt | AC | 88 ms | 6732 KB |
1
|
in15.txt | AC | 158 ms | 6824 KB |
1
|
in16.txt | AC | 85 ms | 6792 KB |
1
|
in17.txt | AC | 44 ms | 2152 KB |
1
|
in18.txt | AC | 51 ms | 4508 KB |
1
|
in19.txt | AC | 62 ms | 6192 KB |
1
|
in20.txt | AC | 21 ms | 676 KB |
1
|
in21.txt | AC | 21 ms | 632 KB |
1
|
in22.txt | AC | 23 ms | 584 KB |
1
|
in23.txt | AC | 52 ms | 2208 KB |
1
|
in24.txt | AC | 76 ms | 4048 KB |
1
|
in25.txt | AC | 45 ms | 6824 KB |
1
|
in26.txt | AC | 59 ms | 6788 KB |
1
|
in27.txt | AC | 43 ms | 6884 KB |
1
|
in28.txt | AC | 50 ms | 6852 KB |
1
|
in29.txt | AC | 14 ms | 552 KB |
1
|
in30.txt | AC | 21 ms | 504 KB |
1
|
sample01.txt | AC | 49 ms | 580 KB |
1
|
sample02.txt | AC | 18 ms | 664 KB |
1
|