QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#419385#8416. Dzielniki [B]Naganohara_Yoimiya1 740ms63172kbC++143.3kb2024-05-23 21:12:182024-05-23 21:12:22

Judging History

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

  • [2024-05-23 21:12:22]
  • 评测
  • 测评结果:1
  • 用时:740ms
  • 内存:63172kb
  • [2024-05-23 21:12:18]
  • 提交

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==d);
}

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(k>=26){
		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;
}

詳細信息

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 595ms
memory: 62992kb

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:

Accepted: queries used = 5228.

result:

ok 

Test #2:

score: 1
Accepted
time: 606ms
memory: 62556kb

input:

50 100000 50000 1000000000000
21469
57104
22446
74024
60004
7599
18880
42347
76178
83980
96162
67460
33521
66752
35898
60176
83640
97657
55440
58256
4483
15397
7528
42761
18012
741
45496
43216
80215
99629
62890
29063
77462
98071
27424
32544
47601
98801
53915
3299
38560
96577
24569
10735
75026
52968
...

output:

Accepted: queries used = 5311.

result:

ok 

Test #3:

score: 1
Accepted
time: 585ms
memory: 62564kb

input:

50 100000 50000 1000000000000
11001
35509
7673
24690
15443
22930
85249
2442
65424
21223
65223
91708
37676
68800
98505
70082
53761
70029
43022
17965
67076
23681
68973
40488
84861
99396
72157
48846
77583
16679
18879
95548
8806
64669
21819
37682
33092
28505
32069
94584
11546
43718
16791
87013
95852
893...

output:

Accepted: queries used = 4761.

result:

ok 

Test #4:

score: 1
Accepted
time: 603ms
memory: 63172kb

input:

50 100000 50000 1000000000000
93976
96052
99996
98628
98776
92381
99938
91670
71221
81945
99650
78522
50592
94448
98247
97344
99997
78935
84535
99572
91874
99119
99242
79099
99678
78737
72474
99966
99297
98800
92568
96640
98771
99452
94930
98479
99024
97127
98334
85199
91969
99900
96749
97754
95988
...

output:

Accepted: queries used = 5340.

result:

ok 

Test #5:

score: 1
Accepted
time: 609ms
memory: 61796kb

input:

50 100000 50000 1000000000000
99861
97227
99965
99800
81573
86111
95881
90856
95494
98052
92544
99501
99293
98305
93153
98858
98448
99031
98925
97265
91357
96759
99204
99930
99648
84420
99965
96328
99657
98260
79899
92365
99519
82788
96039
95438
78665
98042
99570
96899
77557
99941
88088
99276
97363
...

output:

Accepted: queries used = 5341.

result:

ok 

Test #6:

score: 1
Accepted
time: 740ms
memory: 61836kb

input:

50 100000 50000 1000000000000
88455
98295
98552
97350
99585
94633
92948
95778
99872
99849
99749
97597
99139
92554
99317
99373
99836
97283
96490
91063
84414
88108
95620
92364
99829
95010
90394
99309
98432
99754
74609
99744
71161
81694
99966
99798
99242
98336
92819
81590
99749
98143
87421
89941
63828
...

output:

Accepted: queries used = 4953.

result:

ok 

Test #7:

score: 1
Accepted
time: 595ms
memory: 61152kb

input:

50 100000 50000 1000000000000
98297
93305
82937
78725
73721
69977
65529
62201
59042
55289
52481
49145
46649
41465
39359
36857
34985
32761
31097
27641
26237
24569
23321
20729
19676
18425
17489
16377
15545
13817
13115
12281
11657
10361
9209
8741
8185
7769
6905
6554
6137
5825
5177
4601
4367
4089
3881
3...

output:

Accepted: queries used = 4417.

result:

ok 

Test #8:

score: 1
Accepted
time: 595ms
memory: 62800kb

input:

50 100000 50000 1000000000000
31397
31398
31396
31399
31393
31402
31388
31407
31381
31414
31372
31423
31361
31434
31348
31447
31333
31462
31316
31479
31297
31498
31276
31519
31253
31542
31228
31567
31201
31594
31172
31623
31141
31654
31108
31687
31073
31722
31036
31759
30997
31798
30956
31839
30913
...

output:

Accepted: queries used = 4943.

result:

ok 

Test #9:

score: 1
Accepted
time: 546ms
memory: 62772kb

input:

50 100000 50000 1000000000000
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

output:

Accepted: queries used = 2196.

result:

ok 

Test #10:

score: 1
Accepted
time: 609ms
memory: 62648kb

input:

50 100000 50000 1000000000000
100000
99999
99998
99997
99996
99995
99994
99993
99992
99991
99990
99989
99988
99987
99986
99985
99984
99983
99982
99981
99980
99979
99978
99977
99976
99975
99974
99973
99972
99971
99970
99969
99968
99967
99966
99965
99964
99963
99962
99961
99960
99959
99958
99957
99956...

output:

Accepted: queries used = 4722.

result:

ok 

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 601ms
memory: 61348kb

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: too many queries

result:

wrong answer 

Subtask #3:

score: 0
Time Limit Exceeded

Test #21:

score: 1
Accepted
time: 592ms
memory: 62228kb

input:

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

output:

Accepted: queries used = 1344.

result:

ok 

Test #22:

score: 1
Accepted
time: 606ms
memory: 62596kb

input:

10 1000000000 50000 1000000000000
708800233
175172934
173179851
979063909
265733080
344682863
958178918
989549919
409032428
280453549

output:

Accepted: queries used = 1491.

result:

ok 

Test #23:

score: 1
Accepted
time: 726ms
memory: 62740kb

input:

10 1000000000 50000 1000000000000
701712832
986726652
113619980
366011803
189676570
26736014
248627457
379195285
411344794
954348086

output:

Accepted: queries used = 1355.

result:

ok 

Test #24:

score: 1
Accepted
time: 582ms
memory: 62532kb

input:

10 1000000000 50000 1000000000000
961848720
913017579
933822749
997780972
982478374
965397362
993585954
786461482
886524960
851655942

output:

Accepted: queries used = 1279.

result:

ok 

Test #25:

score: 1
Accepted
time: 587ms
memory: 62668kb

input:

10 1000000000 50000 1000000000000
991792574
658024835
748402786
944137501
993731043
922310034
989857114
999543156
996908456
760833893

output:

Accepted: queries used = 1289.

result:

ok 

Test #26:

score: 1
Accepted
time: 605ms
memory: 61344kb

input:

10 1000000000 50000 1000000000000
876899138
905535224
983253823
874432418
972319229
996893036
993091756
936474125
752025977
675980729

output:

Accepted: queries used = 1485.

result:

ok 

Test #27:

score: 0
Time Limit Exceeded

input:

10 1000000000 50000 1000000000000
967458809
918330041
905969657
859963385
816293369
805306361
774840971
764411897
725594105
688747529

output:

Unauthorized output

result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #31:

score: 0
Time Limit Exceeded

input:

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

output:

Unauthorized output

result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #41:

score: 0
Time Limit Exceeded

input:

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

output:

Unauthorized output

result:


Subtask #6:

score: 0
Time Limit Exceeded

Test #51:

score: 0
Time Limit Exceeded

input:

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

output:

Unauthorized output

result:


Subtask #7:

score: 0
Time Limit Exceeded

Test #61:

score: 0
Time Limit Exceeded

input:

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

output:

Unauthorized output

result:


Subtask #8:

score: 0
Time Limit Exceeded

Test #71:

score: 0
Time Limit Exceeded

input:

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

output:

Unauthorized output

result:


Subtask #9:

score: 0
Time Limit Exceeded

Test #81:

score: 0
Time Limit Exceeded

input:

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

output:

Unauthorized output

result:


Subtask #10:

score: 0
Time Limit Exceeded

Test #91:

score: 0
Time Limit Exceeded

input:

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

output:

Unauthorized output

result: