結果

問題 No.2620 Sieve of Coins
ユーザー 👑 kmjpkmjp
提出日時 2024-02-08 00:25:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 408 ms / 2,000 ms
コード長 2,313 bytes
コンパイル時間 2,309 ms
コンパイル使用メモリ 204,468 KB
実行使用メモリ 19,200 KB
最終ジャッジ日時 2024-02-08 00:25:28
合計ジャッジ時間 11,941 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
19,072 KB
testcase_01 AC 92 ms
19,072 KB
testcase_02 AC 90 ms
19,072 KB
testcase_03 AC 101 ms
19,072 KB
testcase_04 AC 194 ms
19,072 KB
testcase_05 AC 88 ms
19,072 KB
testcase_06 AC 88 ms
19,072 KB
testcase_07 AC 111 ms
19,072 KB
testcase_08 AC 98 ms
19,072 KB
testcase_09 AC 94 ms
19,072 KB
testcase_10 AC 96 ms
19,072 KB
testcase_11 AC 98 ms
19,072 KB
testcase_12 AC 96 ms
19,072 KB
testcase_13 AC 93 ms
19,072 KB
testcase_14 AC 94 ms
19,072 KB
testcase_15 AC 89 ms
19,072 KB
testcase_16 AC 95 ms
19,072 KB
testcase_17 AC 94 ms
19,072 KB
testcase_18 AC 130 ms
19,072 KB
testcase_19 AC 107 ms
19,072 KB
testcase_20 AC 93 ms
19,072 KB
testcase_21 AC 100 ms
19,072 KB
testcase_22 AC 106 ms
19,072 KB
testcase_23 AC 96 ms
19,072 KB
testcase_24 AC 94 ms
19,072 KB
testcase_25 AC 94 ms
19,072 KB
testcase_26 AC 96 ms
19,072 KB
testcase_27 AC 96 ms
19,072 KB
testcase_28 AC 98 ms
19,072 KB
testcase_29 AC 114 ms
19,072 KB
testcase_30 AC 90 ms
19,072 KB
testcase_31 AC 135 ms
19,072 KB
testcase_32 AC 105 ms
19,072 KB
testcase_33 AC 92 ms
19,072 KB
testcase_34 AC 95 ms
19,072 KB
testcase_35 AC 97 ms
19,072 KB
testcase_36 AC 113 ms
19,072 KB
testcase_37 AC 108 ms
19,072 KB
testcase_38 AC 206 ms
19,072 KB
testcase_39 AC 164 ms
19,072 KB
testcase_40 AC 176 ms
19,072 KB
testcase_41 AC 151 ms
19,072 KB
testcase_42 AC 194 ms
19,072 KB
testcase_43 AC 295 ms
19,072 KB
testcase_44 AC 308 ms
19,072 KB
testcase_45 AC 91 ms
19,072 KB
testcase_46 AC 101 ms
19,072 KB
testcase_47 AC 104 ms
19,072 KB
testcase_48 AC 145 ms
19,072 KB
testcase_49 AC 129 ms
19,072 KB
testcase_50 AC 101 ms
19,072 KB
testcase_51 AC 201 ms
19,072 KB
testcase_52 AC 133 ms
19,072 KB
testcase_53 AC 121 ms
19,072 KB
testcase_54 AC 287 ms
19,200 KB
testcase_55 AC 388 ms
19,200 KB
testcase_56 AC 408 ms
19,200 KB
testcase_57 AC 383 ms
19,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

ll L;
int N;
ll A[1010];
int p2[1010],p3[1010];

const int prime_max = 2000000;
int MU[prime_max+1];
int num[prime_max+1];

void mebius() {
	int i,j;
	for(i=1;i<=prime_max;i++) MU[i]=1, num[i]=i;
	for(int i=2;i<=prime_max;i++) if(num[i]==i) {
		for(j=i;j<=prime_max;j+=i) {
			int x=0;
			MU[j]=-MU[j];
			while(num[j]%i==0) {
				x++;
				num[j]/=i;
			}
			if(x>=2) MU[j]=0;
		}
	}
}

ll G(ll L,int a,int b) {
	static ll memo[1<<20][2][2];
	if(L==0) return 0;
	if(memo[L][a][b]) return memo[L][a][b];
	ll ret=0;
	for(ll i=1;i*i<=L;i++) {
		ll k=0;
		if(i%2==0&&a) k=0;
		else if(i%3==0&&b) k=0;
		else {
			ll pat=L/(i*i);
			k=pat;
			if(a) k-=pat/2;
			if(b) k-=pat/3;
			if(a&&b) k+=pat/6;
		}
		
		ret+=MU[i]*k;
	}
	return ret;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	int C[60][60]={};
	mebius();
	cin>>L>>N;
	FOR(i,N) {
		cin>>A[i];
		while(A[i]%2==0) {
			p2[i]++;
			A[i]/=2;
		}
		while(A[i]%3==0) {
			p3[i]++;
			A[i]/=3;
		}
		C[p2[i]][p3[i]]++;
	}
	
	ll ret=0;
	int mask;
	FOR(i,56) FOR(j,56) {
		FOR(mask,1<<4) if(mask) {
			int num=0;
			if(mask&1) num+=C[i][j];
			if(mask&2) num+=C[i][j+1];
			if(mask&4) num+=C[i+1][j];
			if(mask&8) num+=C[i+1][j+1];
			if(num==__builtin_popcount(mask)) {
				if(mask==2||mask==4||mask==8) continue;
				if(mask==12||mask==10) continue;
				ll V=L;
				FOR(k,i+((mask&12)>0)) V/=2;
				FOR(k,j+((mask&10)>0)) V/=3;
				V=G(V,((mask&12)>0),((mask&10)>0));
				FOR(k,__builtin_popcount(mask)-1) V=V*-2;
				ret+=V;
			}
		}
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0