QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1584#933011#10204. Heretical … MöbiusN_z_ship2077Success!2025-03-13 10:52:232025-03-13 10:52:24

Details

Extra Test:

Time Limit Exceeded

input:

10111011001010111001
10011001101010101011
10000001101110111011
00011010001010111011
00111001101000110001
10111010001110110001
00111011101110011011
00001001101100111001
10111010000010111000
10111011001100110011

output:


result:


IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#933011#10204. Heretical … Möbiusship2077TL 282ms3840kbC++231.4kb2025-03-13 10:35:272025-03-13 10:52:44

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int lim=1e9,N=32000,m[]={4,9,25,49,121,169},inv[]={1,7,16,30,67,9},k[]={1,4,36,900,44100,5336100,901800900};
int ans,num,cnt,x[6],pri[N];
vector<int>vec[6];
string s,str;bool vis[N+5];
void init(int n){
	for (int i=2;i<=n;i++)
		if (!vis[i]){ pri[++num]=i*i;
			for (int j=i<<1;j<=n;j+=i)
				vis[j]=1;
		}
}
bool mu(int x){
	for (int i=1;i<=num&&pri[i]<=x;i++)
		if (!(x%pri[i])) return 0;
	return 1;
}
void upd(int x){
	if (x>ans) return ;
	for (int i=1;i<=200;i++)
		if (mu(x+i)!=s[i]-'0')
			return ;
	ans=x;
}
void exgcd(int a,int b,int &x,int &y){
	if (!b) return x=1,y=0,void();
	exgcd(b,a%b,y,x);y-=a/b*x;
}
void CRT(){ int b=0;
	for (int i=0;i<6;i++)
		b+=1ll*(x[i]-b%m[i]+m[i])%m[i]*inv[i]%m[i]*k[i];
	while (b+200<=lim) upd(b),b+=k[6];
}
void dfs(int now){
	if (now==6) return CRT(),void();
	for (auto tmp:vec[now]) x[now]=tmp,dfs(now+1);
}
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	s=" ";
	for (int i=0;i<10;i++)
		cin>>str,s+=str;
	init(N);
	for (int i=1;i<=200;i++) cnt+='1'-s[i];
	if (cnt<72||cnt>93) return cout<<-1<<endl,0;
	for (int k=0;k<6;k++)
		for (int i=1;i<=m[k];i++){
			int fl=1;
			for (int j=i;j<=200;j+=m[k])
				if (s[j]=='1') {fl=0;break;}
			if (fl) vec[k].push_back(m[k]-i);
		}
	ans=INT_MAX;dfs(0);
	cout<<(ans==INT_MAX?-1:ans+1)<<endl;
	return 0;
}