Submission #52324110


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ll long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << ": " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(int x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int MOD=998244353;

ll qexp(ll b,ll p,int m){
    ll res=1;
    while (p){
        if (p&1) res=(res*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return res;
}

ll fix(ll i){
	i%=MOD;
	if (i<0) i+=MOD;
	return i;
}


int n,k;
vector<ii> p;
int arr[200005];

int brr[1<<20]; 

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>n>>k;
	rep(x,1,n+1) cin>>arr[x];
	
	for (int x=2;x<=100000005;x++) if (k%x==0){
		int curr=0;
		while (k%x==0){
			curr++;
			k/=x;
		}
		p.pub({x,curr});
	}
	if (k!=1) p.pub({k,1});
	
	// for (auto [a,b]:p) cout<<a<<" "<<b<<endl;
	
	rep(x,1,n+1){
		bool bad=false;
		int bm=0;
		
		rep(y,0,sz(p)){
			int curr=0;
			while (arr[x]%p[y].fi==0){
				curr++;
				arr[x]/=p[y].fi;
			}
			
			if (curr>p[y].se) bad=true;
			if (curr<p[y].se) bm|=1<<y;
		}
		
		if (arr[x]>1) bad=true;
		
		if (!bad) brr[bm]++;
	}
	
	rep(b,0,20){
		rep(bm,0,1<<20) if ((bm>>b)&1) brr[bm^(1<<b)]+=brr[bm];
	}
	
	int ans=0;
	rep(x,0,1<<20){
		if (__builtin_parity(x)) ans=fix(ans-qexp(2,brr[x],MOD));
		else ans=fix(ans+qexp(2,brr[x],MOD));
	}
	
	cout<<ans<<endl;
}

Submission Info

Submission Time
Task F - Subsequence LCM
User errorgorn
Language C++ 20 (gcc 12.2)
Score 525
Code Size 1885 Byte
Status AC
Exec Time 366 ms
Memory 13388 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 3
AC × 37
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 02_big_01.txt, 02_big_02.txt, 02_big_03.txt, 02_big_04.txt, 02_big_05.txt, 02_big_06.txt, 02_big_07.txt, 02_big_08.txt, 02_big_09.txt, 02_big_10.txt, 02_big_11.txt, 02_big_12.txt, 02_big_13.txt, 02_big_14.txt, 02_big_15.txt, 02_big_16.txt, 02_big_17.txt, 02_big_18.txt, 02_big_19.txt, 02_big_20.txt, 02_big_21.txt, 02_big_22.txt, 02_big_23.txt, 02_big_24.txt, 02_big_25.txt, 02_big_26.txt, 02_big_27.txt, 02_big_28.txt, 02_big_29.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 311 ms 11668 KiB
00_sample_02.txt AC 311 ms 11664 KiB
00_sample_03.txt AC 311 ms 11736 KiB
01_small_01.txt AC 312 ms 11692 KiB
01_small_02.txt AC 312 ms 11692 KiB
01_small_03.txt AC 312 ms 11708 KiB
01_small_04.txt AC 312 ms 11696 KiB
01_small_05.txt AC 312 ms 11696 KiB
02_big_01.txt AC 334 ms 13128 KiB
02_big_02.txt AC 332 ms 13264 KiB
02_big_03.txt AC 331 ms 13184 KiB
02_big_04.txt AC 332 ms 13256 KiB
02_big_05.txt AC 334 ms 13260 KiB
02_big_06.txt AC 330 ms 13264 KiB
02_big_07.txt AC 336 ms 13260 KiB
02_big_08.txt AC 334 ms 13228 KiB
02_big_09.txt AC 331 ms 13212 KiB
02_big_10.txt AC 328 ms 13184 KiB
02_big_11.txt AC 361 ms 13224 KiB
02_big_12.txt AC 360 ms 13264 KiB
02_big_13.txt AC 361 ms 13272 KiB
02_big_14.txt AC 359 ms 13248 KiB
02_big_15.txt AC 359 ms 13248 KiB
02_big_16.txt AC 362 ms 13300 KiB
02_big_17.txt AC 356 ms 13388 KiB
02_big_18.txt AC 358 ms 13332 KiB
02_big_19.txt AC 358 ms 13260 KiB
02_big_20.txt AC 360 ms 13232 KiB
02_big_21.txt AC 361 ms 13268 KiB
02_big_22.txt AC 355 ms 13332 KiB
02_big_23.txt AC 326 ms 13128 KiB
02_big_24.txt AC 327 ms 13256 KiB
02_big_25.txt AC 366 ms 13232 KiB
02_big_26.txt AC 362 ms 13264 KiB
02_big_27.txt AC 354 ms 13324 KiB
02_big_28.txt AC 318 ms 13260 KiB
02_big_29.txt AC 326 ms 13268 KiB