QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#419372#8416. Dzielniki [B]Naganohara_Yoimiya0 14866ms63012kbC++143.3kb2024-05-23 21:03:502024-05-23 21:03:52

Judging History

你现在查看的是最新测评结果

  • [2024-05-23 21:03:52]
  • 评测
  • 测评结果:0
  • 用时:14866ms
  • 内存:63012kb
  • [2024-05-23 21:03:50]
  • 提交

answer

#include"dzilib.h"
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define int long long
mt19937_64 rnd(20070819);

namespace PR{

int TEST_P[12]={2,3,5,7,11,13,17,19,23,29,31,37};

int mul(int x,int y,int p){
	__int128 a=x,b=y,c=p;
	return (int)(a*b%p);
}

int ksm(int x,int y,int p){
	int ans=1;
	for(int i=y;i;i>>=1,x=mul(x,x,p))if(i&1)ans=mul(ans,x,p);
	return ans;
}

bool chk(int a,int n){
	if(a>=n)return 1;
	int w=n-1,t=0;while(w%2==0)w/=2,t++;
	int x=ksm(a,w,n);
	for(int i=1;i<=t;i++){
		int y=mul(x,x,n);
		if(y==1&&x!=1&&x!=n-1)return 0;
		x=y;
	}
	if(x!=1)return 0;
	return 1;
}

bool is_prime(int n){
	for(int i=0;i<12;i++)if(!chk(TEST_P[i],n))return 0;
	return 1;
}

map<int,int>mp;

int randint(int l,int r){
	return rnd()%(r-l+1)+l;
}

int gcd(int x,int y){return y?gcd(y,x%y):x;}

int f(int x,int c,int p){
	__int128 xx=x,cc=c,pp=p;
	return (int)((xx*xx+cc)%pp);
}

int get(int n){
	// cout<<"get n = "<<n<<endl;
	if(n<=10000){
		for(int i=2;i*i<=n;i++)if(n%i==0)return i;
	}
	while(1){
		int x=randint(0,n-1),c=randint(0,n-1),p=f(x,c,n),q=f(f(x,c,n),c,n);
		if(p==q)continue;
		do{
			int t=1;
			for(int i=1;i<=128;i++){
				p=f(p,c,n),q=f(f(q,c,n),c,n);
				if(p==q||(p-q+n)%n==0)break;
				t=mul(t,(p-q+n)%n,n);
			}
			int d=gcd(n,t);
			if(d>1&&d!=n)return d;
		}while(p!=q);
	}
}

void solve(int n){
	// cout<<"solve n = "<<n<<endl;
	if(n==1)return ;
	if(is_prime(n)){mp[n]++;return ;}
	int x=get(n);
	solve(x),solve(n/x);
}

}

using PR::mp;

int P[10000000],pc=0;
bool chk_divs(int n,int d){
	if(__builtin_ctzll(n)<=12)return true;
	ll ans=1;
	for(int i=1;P[i]*P[i]<=n&&i<=pc;i++){
		int c=0;
		while(n%P[i]==0)n/=P[i],c++;
		ans*=(c+1);
		if(d%ans!=0)return false;
	}
	if(n>1)ans<<=1;
	return (ans==d);
	// mp.clear(),PR::solve(n);
	// ll ans=1;
	// cout<<"calc divs n = "<<n<<endl;
	// for(auto [x,y]:mp)ans*=(y+1);
	// return ans;
}

map<ll,ll>Map;
ll D=0,N;
ll qry(ll x){
	// cout<<"qry x = "<<1000+x<<endl;
	if(Map.find(x)!=Map.end())return Map[x];
	return Map[x]=Ask(x+D);
}

ll dfs(int k,ll now){ // x mod 2^k == now
	// if((1ll<<k)>N+D)return now;
	if((1ll<<(k+20))>N+D){
		int M=(1ll<<k);
		auto chk=[&](int x){
			// cout<<"try x = "<<x<<endl;
			for(auto [A,B]:Map)if(!chk_divs(x+A,B))return false;
			return true;
		};
		for(int x=now;x<=N+D;x+=M)if(chk(x))return x;
		return -1;
	}
	
	// cout<<"dfs k,now = "<<k<<" "<<now<<endl;
	// if(k==2&&now!=0)return -1;

	ll ad=(1ll<<k)-now;ad%=(1ll<<k);
	// cout<<"ad = "<<ad<<endl;
	for(int y=0;y<=3;y++){
		ll yy=(1ll<<k)*y;
		ll W=qry(ad+yy);
		// cout<<"y = "<<y<<" yy = "<<yy<<" W = "<<W<<endl;
		if(W%(k+2)==0){
			ll M=(1ll<<(k+2));
			ll xx=(1ll<<(k+1));
			xx=xx-ad-yy;
			xx=(xx%M+M)%M;
			ll ret=dfs(k+2,xx);
			if(ret!=-1)return ret;
		}
	}
	return -1;
}

ll C;
void solve(){
	Map.clear();
	D=0;
	// D=rnd()%(N/10);
	// cout<<"C = "<<C<<" D = "<<D<<endl;
	ll ret=dfs(0,0);
	Answer(ret-D);
}

bitset<100000001>vis;
signed main(){
	int tt=GetT(),Q=GetQ();
	C=GetC(),N=GetN();
	
	int V=1e8;
	int cnt=0;
	for(int i=2;i<=V;i++){
		if(!vis[i]){
			P[++pc]=i;
			for(int j=i+i;j<=V;j+=i)vis[j]=true;
		}
	}
	// cout<<"pc = "<<pc<<endl;
	// cout<<"T,Q,N,C = "<<tt<<" "<<Q<<" "<<N<<" "<<C<<endl;
	while(tt--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 518ms
memory: 62744kb

input:

50 100000 50000 1000000000000
49108
86361
48807
44296
98962
74228
70938
50085
85439
82491
61850
10270
86867
40660
48433
67675
57312
17321
8228
87878
61853
80754
9880
65714
55443
34797
89187
44610
75431
56726
52425
16106
49808
75351
46368
19446
65264
39323
25273
46629
98
24463
76734
54088
12393
93157...

output:

ERROR: expected 49108, found 0

result:

wrong answer 

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 513ms
memory: 62304kb

input:

50 1000000 5000 1000000000000
986587
791769
338733
959743
466876
613054
887723
862451
853797
721415
115910
736804
796748
950095
362863
419090
786887
27917
364483
289769
26581
70926
685791
12202
554610
768721
279241
297080
445667
441723
529286
230179
985659
690926
297172
606535
540585
426446
300803
5...

output:

ERROR: expected 986587, found 0

result:

wrong answer 

Subtask #3:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 501ms
memory: 62248kb

input:

10 1000000000 50000 1000000000000
408103384
716411227
312685147
924284703
375298759
152825423
311623701
481729457
215396950
9146195

output:

ERROR: expected 408103384, found 146

result:

wrong answer 

Subtask #4:

score: 0
Time Limit Exceeded

Test #31:

score: 1
Accepted
time: 14866ms
memory: 62076kb

input:

10 100000000000000 5000 100000000000000000
60077435990701
17220541740604
64191465861673
55745499051041
92001632467345
9358956369292
35872866769179
78367022100297
7839460363340
34668026591527

output:

Accepted: queries used = 2273.

result:

ok 

Test #32:

score: 0
Accepted
time: 14421ms
memory: 61444kb

input:

10 100000000000000 5000 100000000000000000
88121892592529
85914457772331
64820859892492
18511079650278
299427612042
75385736059996
11105819324991
59795687515522
62238846663367
45209091190862

output:

Accepted: queries used = 1739.

result:

ok 

Test #33:

score: 0
Accepted
time: 12180ms
memory: 62040kb

input:

10 100000000000000 5000 100000000000000000
2956493283702
37054531818788
24751224113458
98522676264660
75963297689661
94976206952005
85847054998349
6799114844914
1093241188178
83862808454713

output:

Accepted: queries used = 1179.

result:

ok 

Test #34:

score: -1
Time Limit Exceeded

input:

10 100000000000000 5000 100000000000000000
97840336710800
99198301370354
99369233611652
99984973899907
98475020071503
96850565692225
91725282899184
96525587282098
99961045964851
95768078773435

output:

Unauthorized output

result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #41:

score: 1
Accepted
time: 11501ms
memory: 61848kb

input:

10 100000000000000 2000 100000000000000000
12494380076190
85448577530879
31501976723503
61560401637840
9958432442859
68538788138133
81056300713749
31455642088461
52813858531796
2350217441027

output:

Accepted: queries used = 1776.

result:

ok 

Test #42:

score: -1
Time Limit Exceeded

input:

10 100000000000000 2000 100000000000000000
70753637558992
6970224422539
1583632219113
48358662514863
26633122232146
99341476503640
79348403772465
33646132450446
95640458860588
32377752455635

output:

Unauthorized output

result:


Subtask #6:

score: 0
Wrong Answer

Test #51:

score: 0
Wrong Answer
time: 7128ms
memory: 62184kb

input:

10 100000000000000 1300 100000000000000000
93861841503524
187801688618
12767914004896
68441979369935
44276894335941
10366130300247
10581531522622
34683620486862
71739885742802
31789387511772

output:

ERROR: too many queries

result:

wrong answer 

Subtask #7:

score: 0
Wrong Answer

Test #61:

score: 0
Wrong Answer
time: 9172ms
memory: 63012kb

input:

10 100000000000000 950 100000000000000000
89476806232027
12353673422544
87587374109960
29662216144897
59695535958606
16446701644855
15698587958167
76032905298130
18875210693225
2202458936163

output:

ERROR: too many queries

result:

wrong answer 

Subtask #8:

score: 0
Wrong Answer

Test #71:

score: 0
Wrong Answer
time: 5658ms
memory: 62396kb

input:

10 100000000000000 820 100000000000000000
57380646951677
24500445660413
52513218855562
35936833055954
21061776201610
17990465203024
53667291726216
50437972694073
8891884060027
40201586063900

output:

ERROR: too many queries

result:

wrong answer 

Subtask #9:

score: 0
Wrong Answer

Test #81:

score: 0
Wrong Answer
time: 6782ms
memory: 62828kb

input:

10 100000000000000 750 100000000000000000
5121346638871
87604132110850
89767773421324
36910678760633
22317088453717
9150554156208
86627018380188
91455697966830
39854585335842
25531102467103

output:

ERROR: too many queries

result:

wrong answer 

Subtask #10:

score: 0
Wrong Answer

Test #91:

score: 0
Wrong Answer
time: 4131ms
memory: 61808kb

input:

10 100000000000000 720 100000000000000000
32571246806419
17047845628559
72028252544868
84189424781123
34278867527450
31844169904318
25833108322349
14895620716019
41844198477918
35390870210849

output:

ERROR: too many queries

result:

wrong answer