QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#404404#8336. Indeterminate EquationLiWenXWA 3ms6988kbC++203.1kb2024-05-03 21:41:432024-10-13 18:52:50

Judging History

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

  • [2024-11-06 12:52:58]
  • hack成功,自动添加数据
  • (/hack/1138)
  • [2024-10-17 13:41:28]
  • hack成功,自动添加数据
  • (/hack/1008)
  • [2024-10-13 18:52:50]
  • 管理员手动重测本题所有得分≥97分的提交记录
  • 测评结果:WA
  • 用时:3ms
  • 内存:6988kb
  • [2024-09-09 21:13:16]
  • hack成功,自动添加数据
  • (/hack/812)
  • [2024-09-04 17:57:27]
  • hack成功,自动添加数据
  • (/hack/801)
  • [2024-08-25 02:46:37]
  • hack成功,自动添加数据
  • (/hack/787)
  • [2024-05-04 13:35:34]
  • hack成功,自动添加数据
  • (/hack/610)
  • [2024-05-04 13:28:41]
  • hack成功,自动添加数据
  • (/hack/609)
  • [2024-05-03 21:54:55]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:97
  • 用时:3ms
  • 内存:4948kb
  • [2024-05-03 21:51:59]
  • hack成功,自动添加数据
  • (/hack/608)
  • [2024-05-03 21:41:43]
  • 评测
  • 测评结果:100
  • 用时:3ms
  • 内存:4964kb
  • [2024-05-03 21:41:43]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
__int128 quickpow(__int128 a,int b){
	__int128 ret=1;
	while(b){
		if(b&1) ret=ret*a;
		a=a*a;
		b>>=1;
	}return ret;
}
int prime[1000001],maxn[100001],tot;
bool isprime[100001];
void shai(int n=1e5){
	fill(isprime+1,isprime+1+n,1);
	isprime[1]=0;
	for(int i=2;i<=n;i++){
		if(isprime[i]){
			prime[++tot]=i;
			maxn[i]=i;
		}
		for(int j=1;j<=tot&&prime[j]*i<=n;j++){
			maxn[prime[j]*i]=maxn[i];
			isprime[prime[j]*i]=0;
			if(i%prime[j]==0) break;
		}
	}
}
int mul(int a,int b,int mod){
	int d=a*(long double)b/mod;
	int ret=a*b-d*mod;
	if(ret<0)ret+=mod;
	if(ret>=mod) ret-=mod;
	return ret;
}
int quickpow(int a,int b,int mod){
	int ret=1;
	while(b){
		if(b&1) ret=mul(ret,a,mod)%mod;
		a=mul(a,a,mod)%mod;
		b>>=1;
	}return ret;
}
bool Isprime(int a,int p){
	int d=p-1;
	if(quickpow(a,d,p)!=1) return 0;
	while(!(d&1)){
		d>>=1;
		int t=quickpow(a,d,p);
		if(t==p-1) return 1;
		else if(t!=1) return 0;
	}return 1;
}
int List[]={2,3,5,7,11,13,17,19,23,29,31,37};
bool Mr(int p){
	if(p<=1e5) return isprime[p];
	for(int u:List){
		if(!Isprime(u,p)) return 0;
	}
	return 1;
}
mt19937 rd(time(NULL));
int ran(int l,int r){
	return rd()%(r-l+1)+l;
}
int Pr(int n){
	int x=ran(0,n-1),y=x;
	int c=ran(3,n-1);
	x=(mul(x,x,n)+c)%n;
	y=(mul(y,y,n)+c)%n,y=(mul(y,y,n)+c)%n;
	for(int lim=1;x!=y;lim=min(128ll,lim<<1)){
		int s=1;
		for(int i=0;i<lim;i++){
			int S=mul(s,abs(x-y),n);
			if(!S) break;
			s=S;
			x=(mul(x,x,n)+c)%n;
			y=(mul(y,y,n)+c)%n,y=(mul(y,y,n)+c)%n;
		}
		int d=__gcd(s,n);
		if(d!=1) return d;
	}return n;
}
vector<int> vec;
void solve(int x){
	if(x<=1e5){
		while(x!=1){
			vec.push_back(maxn[x]);
			x/=maxn[x];
		}
		return ;
	}
	if(Mr(x)){
		vec.push_back(x);
		return ;
	}
	int t=Pr(x);
	while(t==x) t=Pr(x);
	solve(t),solve(x/t);
}
int lim=0;
vector<int> ins;
void dfs(int now,int S){
	if(S>lim) return ;
	if(now==vec.size()){
		ins.push_back(S);return ;
	}
	int l=now,r=now;
	while(r+1<vec.size()&&vec[r+1]==vec[l]){
		r++;
	}
	for(int i=0,t=1;i<=r-l+1;i++,t*=vec[l]){
		dfs(r+1,S*t);
	}
}
void solve(){
	vec.clear();ins.clear();
	int n,k;cin>>n>>k;
	lim=pow(n+1,1.0/k);
	while(pow(lim+1,k)<=n+1) lim++;
	while(pow(lim,k)>n+1) lim--;lim--;
	int lim2=pow(n+1,1.0/(k-1));
	while(pow(lim2+1,k-1)<=n+1) lim2++;
	while(pow(lim2,k-1)>n+1) lim2--;lim2--;
	solve(n);
	sort(vec.begin(),vec.end());
	dfs(0,1);
	int ans=0;
//	cout<<lim2<<'\n';
	for(int u:ins){
//		cout<<u<<" ";
		int l=1,r=lim2;
		while(l<=r){
			int mid=(l+r)>>1;
			__int128 C=quickpow(mid+u,k)-quickpow(mid,k);
			if(C==n){
				ans++;break;
			}
			if(C>n){
				r=mid-1;
			}
			else{
				l=mid+1;
			}
		}
//		if(u==1){
//			l=114429;
//			int C=quickpow(l+u,k)-quickpow(l,k);
//			cout<<l<<" "<<r<<' '<<C<<'\n';
//			592570256192463681
//			592571815933494815
//		}
	}
//	cout<<'\n';
	cout<<min(ans,1ll)<<'\n';
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	shai();
	int tt;cin>>tt;
	while(tt--) solve();
}
/*
1
592570256192463681 4
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4868kb

input:

3
7 3
15 4
31 5

output:

1
1
1

result:

ok 3 number(s): "1 1 1"

Test #2:

score: 0
Accepted
time: 3ms
memory: 6324kb

input:

20
409013310800583799 32
70368744177663 46
592570256192463681 4
360020145419649 5
357385021818058297 3
950227088646484702 56
127 7
718303642731669822 3
651621023623339377 45
405657994164855469 3
4095 12
288230376151711743 58
224251587219143167 5
2221626677255791 3
2953488086475199 4
6672460861685157...

output:

0
1
1
1
1
0
1
0
0
1
1
1
1
1
1
1
0
1
0
0

result:

ok 20 numbers

Test #3:

score: 0
Accepted
time: 2ms
memory: 6596kb

input:

20
299663213308337404 3
789663530028185253 15
899102550518872677 5
908651241968426417 38
10161731698203367 3
172563904510845597 3
24904219972305241 3
72057594037927935 56
900135928346130972 6
63 6
32370674179164127 3
638119226609365944 62
67108863 26
257821881508336320 3
815804918211865461 12
910411...

output:

1
0
1
0
1
1
1
1
0
1
1
0
1
1
0
0
1
1
1
1

result:

ok 20 numbers

Test #4:

score: 0
Accepted
time: 2ms
memory: 4920kb

input:

20
987212517904356866 10
625343233082041 3
281474976710655 48
35184372088831 45
8191 13
33554431 25
387412204026720769 3
109355953976006437 3
2198205420145 4
47103092714538256 21
448246606222334791 7
99826963551194419 3
417720736167446718 26
9007199254740991 53
130481423309676535 8
2251799813685247 ...

output:

0
1
1
1
1
1
1
1
1
0
0
1
0
1
0
1
1
1
1
1

result:

ok 20 numbers

Test #5:

score: 0
Accepted
time: 3ms
memory: 6132kb

input:

20
369621295427910453 63
829540864429248940 50
328188506235593452 38
801208558894131272 13
872695838727528838 3
1073741823 30
252424883748225843 19
276360191653207583 13
23680201591411597 3
605336327501498607 29
3368576601423011 5
541099690642302715 3
110139179543268157 3
1073741823 30
5091219638745...

output:

0
0
0
0
1
1
0
0
1
0
1
1
1
1
0
1
1
1
1
1

result:

ok 20 numbers

Test #6:

score: 0
Accepted
time: 2ms
memory: 4956kb

input:

20
8191 13
58185299844488917 3
946219666221344402 19
199313544345127719 42
305224472569938018 6
274877906943 38
8191 13
4398046511103 42
181275224823960757 3
26525260926988201 3
562949953421311 49
4464847706965471 3
457186927518156860 5
158117286447030969 46
549755813887 39
555307613261368 5
4401772...

output:

1
1
0
0
0
1
1
1
1
1
1
1
0
0
1
1
1
0
0
0

result:

ok 20 numbers

Test #7:

score: 0
Accepted
time: 0ms
memory: 6556kb

input:

20
4398046511103 42
833253453410579766 62
409534938012033754 63
72057594037927935 56
536870911 29
34951725759140191 3
90835460846790978 13
16777215 24
2251799813685247 51
699719950959624759 54
248653563296585041 3
421715905914046949 3
605636896545987345 4
524287 19
241759398856733802 6
4935421722667...

output:

1
0
0
1
1
1
0
1
1
0
1
1
1
1
0
0
1
1
1
0

result:

ok 20 numbers

Test #8:

score: 0
Accepted
time: 0ms
memory: 4884kb

input:

20
106552237922246881 3
412052866942149907 3
2147483647 31
796082436742414414 24
408359486510009476 12
63 6
17592186044415 44
118509271529004788 9
3979116231690817 3
262143 18
70368744177663 46
42768140446560097 3
8589934591 33
386734487134757674 12
4503599627370495 52
536870911 29
28823037615171174...

output:

1
1
1
0
0
1
1
0
1
1
1
1
1
0
1
1
1
1
0
1

result:

ok 20 numbers

Test #9:

score: 0
Accepted
time: 2ms
memory: 4992kb

input:

20
134217727 27
83420139097331842 62
274135990917964800 5
434500257687581785 35
501744216766405008 15
451335986349193 5
868853355445748320 13
301001412129614 5
67108863 26
953222376692677434 25
1886006831138137 3
15857519990553792 5
69764165614656105 63
81798613090978231 3
989051271211163304 41
1867...

output:

1
0
1
0
0
1
0
1
1
0
1
1
0
1
0
0
1
1
1
1

result:

ok 20 numbers

Test #10:

score: 0
Accepted
time: 3ms
memory: 4836kb

input:

20
290234946576194630 24
324991611316950487 3
377254568067887797 3
199176477432292800 5
481817525933591580 44
306179318310704225 5
184460035325889819 5
96166909590250592 3
69908027519627596 3
7371051187969 3
562949953421311 49
513570208984730028 6
180646903364861467 3
622083445561687933 56
145588025...

output:

0
1
1
1
0
1
1
1
1
1
1
0
1
0
1
1
1
1
0
1

result:

ok 20 numbers

Test #11:

score: 0
Accepted
time: 0ms
memory: 6164kb

input:

20
70368744177663 46
137438953471 37
72057594037927935 56
1898262015327215 4
593117722299956521 62
81438002329886371 3
399674414175214669 3
215867547011594871 32
584844110936591318 53
159843794446621357 3
54115722785729521 3
278593973273873791 3
741200008753001294 5
62103974292968851 3
7521806114753...

output:

1
1
1
1
0
1
1
0
0
1
1
1
1
1
0
1
1
1
1
1

result:

ok 20 numbers

Test #12:

score: 0
Accepted
time: 2ms
memory: 4868kb

input:

20
15 4
639325486456928631 24
367160239938275019 3
35135369151859768 5
134217727 27
162403073577381280 4
4398046511103 42
849266064473374657 22
467964515935413061 3
8388607 23
137438953471 37
215086822275193505 3
305420275067478247 3
103789388695665446 18
215568298601022841 3
4503599627370495 52
469...

output:

1
0
1
1
1
1
1
0
1
1
1
1
1
0
1
1
1
1
0
1

result:

ok 20 numbers

Test #13:

score: 0
Accepted
time: 0ms
memory: 6352kb

input:

20
137438953471 37
4503599627370495 52
360622068085547772 10
210287245019037702 35
74711655323394929 56
98155419968374287 21
102533060809494095 4
140737488355327 47
933243045575014403 11
72057594037927935 56
149720681727843610 57
1073741823 30
591686942125381888 31
119086672276608015 4
3477271960851...

output:

1
1
0
0
0
0
1
1
0
1
0
1
0
1
1
1
1
0
1
1

result:

ok 20 numbers

Test #14:

score: 0
Accepted
time: 2ms
memory: 6024kb

input:

20
819477969526523940 9
997198472969039861 35
233055230837054597 53
746904402177708777 27
67108863 26
4194303 22
390095551418097427 3
927752109611997442 48
32767 15
390318061363802287 3
686611024540234609 12
20402267600069161 3
698884614026798317 52
562949953421311 49
1550940349430625 4
511 9
759139...

output:

0
0
0
0
1
1
1
0
1
1
0
1
0
1
1
1
0
1
1
0

result:

ok 20 numbers

Test #15:

score: 0
Accepted
time: 2ms
memory: 6988kb

input:

20
347092101157932621 55
523357334205590686 31
686906733435643515 60
120007640497588865 3
347422310624045419 3
301665674749200847 3
866910816105601352 30
5127183360 4
68719476735 36
4194303 22
483964008794649279 18
234063663878120671 3
123845819701080601 3
285423692080282687 3
3912628851220100 5
310...

output:

0
0
0
1
1
1
0
1
1
1
0
1
1
1
1
1
1
0
0
0

result:

ok 20 numbers

Test #16:

score: 0
Accepted
time: 2ms
memory: 4932kb

input:

20
33554431 25
528392007319786400 31
16482551564781760 4
838990357775672509 32
942785412798517385 38
439170874733624419 3
29596780167767827 3
83285573011773301 3
950527866918480 4
2251799813685247 51
4095 12
273991306079656475 5
616699112264653214 52
51492842248899972 25
18785737008450461 15
9959774...

output:

1
0
1
0
0
1
1
1
1
1
1
1
0
0
0
0
0
1
1
1

result:

ok 20 numbers

Test #17:

score: 0
Accepted
time: 2ms
memory: 4932kb

input:

20
2097151 21
3400566422153238 3
631760588083252674 28
167808767206605768 3
323394699435360469 3
335695376290788387 17
35345259238590038 23
39661511301666151 3
102003212137599169 3
131071 17
6017133684009169 3
810416549631456806 61
78371917503410782 3
255 8
292354900238725376 47
394542618557932158 1...

output:

1
1
0
1
1
0
0
1
1
1
1
0
0
1
0
0
1
1
0
1

result:

ok 20 numbers

Test #18:

score: 0
Accepted
time: 0ms
memory: 4984kb

input:

20
8191 13
34450976592326175 39
115992634653776988 30
30841490245990321 3
730558013031329906 56
69661494843438160 4
193199298983587 3
745954000719453413 3
14062568319648604 3
310197905349117863 26
323849701457243377 12
127287856421571104 3
2857372929472969 3
348006386420030269 3
16383 14
524287 19
1...

output:

1
0
0
1
0
1
1
1
1
0
0
1
1
1
1
1
1
1
1
1

result:

ok 20 numbers

Test #19:

score: 0
Accepted
time: 2ms
memory: 6148kb

input:

20
328331949339594705 4
440018735280441037 3
651726196698130641 25
35184372088831 45
560815166864882104 3
1665749740436467 3
725187027841738697 10
97742833161599557 3
628708937360761 3
144115188075855871 57
45246298445492401 3
897305684378354416 4
435615967025653155 62
51390152812182661 3
5497558138...

output:

1
1
0
1
1
1
0
1
1
1
1
1
0
1
1
1
1
1
1
1

result:

ok 20 numbers

Test #20:

score: 0
Accepted
time: 2ms
memory: 6068kb

input:

20
10287757755011200 5
75165632304477787 3
208610838312868531 3
17592186044415 44
262143 18
472628059236086465 33
274441644154738406 14
63 6
70368744177663 46
9120350170569787 3
68931120362029927 3
244281394805637637 3
616071809801248136 44
36284940549244431 3
518603065311042205 31
4294967295 32
650...

output:

1
1
1
1
1
0
0
1
1
1
1
1
0
1
0
1
0
0
0
0

result:

ok 20 numbers

Test #21:

score: 0
Accepted
time: 2ms
memory: 4988kb

input:

20
951043950767860780 64
72057594037927935 56
4398046511103 42
268435455 28
984744214330259561 54
536393574249559831 3
134217727 27
779206543455963934 53
441797261073316237 3
10900408805331694 5
16383 14
755235903449005803 3
235576685499319964 3
4398046511103 42
16992310045669219 3
536870911 29
3180...

output:

0
1
1
1
0
1
1
0
1
1
1
1
1
1
1
1
1
0
0
1

result:

ok 20 numbers

Extra Test:

score: -3
Extra Test Failed : Wrong Answer on 3
time: 2ms
memory: 6596kb

input:

20
14317849 3
14329224 3
14333284 3
14368256 3
14388309 3
14480128 3
14526783 3
14603058 3
14702029 3
14746328 3
14835485 3
14840280 3
14845383 3
14864984 3
14873112 3
14885208 3
14941423 3
14973121 3
15005223 3
15072967 3

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

wrong answer 1st numbers differ - expected: '2', found: '1'