QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#32234#1457. FFT AlgorithmWu_RenAC ✓1164ms17512kbC++111.8kb2022-05-18 09:47:212022-05-18 09:47:22

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-18 09:47:22]
  • 评测
  • 测评结果:AC
  • 用时:1164ms
  • 内存:17512kb
  • [2022-05-18 09:47:21]
  • 提交

answer

#include <bits/stdc++.h>
typedef long long ll;
typedef __int128 lll;
using namespace std;
mt19937_64 rng(time(0));
const int N=11048550;
int K,pr[729510],p=0;
bool isnt[N+10];
ll n,m,np,ny;
int na=0;
void init(){
	for(int i=2;i<=N;i++){
		if(!isnt[i]) pr[++p]=i;
		for(int j=1;j<=p&&pr[j]*i<=N;j++){
			isnt[pr[j]*i]=1;
			if(i%pr[j]==0) break;
		}
	}
}
ll ksm(ll a,ll k){
	ll res=1;
	for(;k;k>>=1,a=a*a) if(k&1) res=res*a;
	return res; 
}
ll ksm(ll a,ll k,ll p){
	ll res=1;
	for(;k;k>>=1,a=lll(a)*a%p) if(k&1) res=lll(res)*a%p;
	return res;
}
void t_r_y(ll p,ll phi){
	if(na) return;
	for(;(double)clock()/CLOCKS_PER_SEC<1.0&&!na;){
		ll y=ksm(rng()%p,phi>>K,p),nw=1;
		bool fl=1;
		for(int j=1;j<(1<<K);j++){
			nw=lll(nw)*y%p;
			if(nw<=1){
				fl=0;
				break;
			}
		}
		nw=lll(nw)*y%p;
		if(nw!=1) fl=0;
		if(fl){
			np=p,na=1,ny=y;
			break;
		}
	}
}
void chk(ll p,int a){
	if(na) return;
	if(p==2){
		if(a-1-(a>=3)>=K) t_r_y(ksm(p,a),ksm(p,a-1-(a>=3)));
		return;
	}
	if((p-1)&((1<<K)-1)) return;
	t_r_y(ksm(p,a),(p-1)*ksm(p,a-1));
}
ll exgcd(ll a,ll b,ll &x,ll &y){
	if(!b) return x=1,y=0,a;
	ll t=exgcd(b,a%b,y,x);
	y-=a/b*x;
	return t;
}
ll mul(ll a,ll b,ll m){
	ll res=0;
	for(;b;b>>=1,a=2*a%m) if(b&1) res=(res+a)%m;
	return res;
}
void exCRT(ll &M,ll &R,ll m,ll r){
	ll x,y,g=exgcd(M,m,x,y),c=(r-R%m+m)%m;
	if(c%g) exit(1);
	x=mul(x,c/g,m/g);
	R+=x*M;
	M*=(m/g);
	R=(R%M+M)%M;
}
int main(){
	init();
	scanf("%lld%d",&n,&K),m=n;
	for(int i=1;i<=p;i++) if(m%pr[i]==0){
		int c=0;
		while(m%pr[i]==0) c++,m/=pr[i];
		chk(pr[i],c);
	}
	for(int j=1;j<=N;j++){
		ll nw=(((ll)j)<<K)+1;
		int c=0;
		while(m%nw==0) c++,m/=nw;
		if(c) chk(nw,c);
	}
	chk(m,1);
	if(!na) puts("-1");
	else{
		exCRT(np,ny,n/np,1%(n/np));
		printf("%lld\n",ny);
	}
}

详细

Test #1:

score: 100
Accepted
time: 349ms
memory: 17408kb

input:

998244353 23

output:

133453162

result:

ok OK valid solution

Test #2:

score: 0
Accepted
time: 168ms
memory: 17464kb

input:

1048576 15

output:

192545

result:

ok OK valid solution

Test #3:

score: 0
Accepted
time: 310ms
memory: 17400kb

input:

3 23

output:

-1

result:

ok OK no solution

Test #4:

score: 0
Accepted
time: 152ms
memory: 17348kb

input:

997261313 15

output:

91794688

result:

ok OK valid solution

Test #5:

score: 0
Accepted
time: 155ms
memory: 17368kb

input:

971604167 15

output:

250445879

result:

ok OK valid solution

Test #6:

score: 0
Accepted
time: 362ms
memory: 17304kb

input:

561972416 15

output:

-1

result:

ok OK no solution

Test #7:

score: 0
Accepted
time: 157ms
memory: 17364kb

input:

998572034 15

output:

341042357

result:

ok OK valid solution

Test #8:

score: 0
Accepted
time: 360ms
memory: 17400kb

input:

127941919 15

output:

-1

result:

ok OK no solution

Test #9:

score: 0
Accepted
time: 298ms
memory: 17388kb

input:

945553409 15

output:

-1

result:

ok OK no solution

Test #10:

score: 0
Accepted
time: 253ms
memory: 17364kb

input:

998244353 23

output:

195169157

result:

ok OK valid solution

Test #11:

score: 0
Accepted
time: 353ms
memory: 17316kb

input:

596468390 23

output:

-1

result:

ok OK no solution

Test #12:

score: 0
Accepted
time: 154ms
memory: 17448kb

input:

813335261 23

output:

-1

result:

ok OK no solution

Test #13:

score: 0
Accepted
time: 160ms
memory: 17244kb

input:

293185311 23

output:

-1

result:

ok OK no solution

Test #14:

score: 0
Accepted
time: 289ms
memory: 17452kb

input:

431142105 23

output:

-1

result:

ok OK no solution

Test #15:

score: 0
Accepted
time: 351ms
memory: 17176kb

input:

545259521 23

output:

-1

result:

ok OK no solution

Test #16:

score: 0
Accepted
time: 154ms
memory: 17408kb

input:

999999998361601 15

output:

630822538949956

result:

ok OK valid solution

Test #17:

score: 0
Accepted
time: 158ms
memory: 17408kb

input:

999956339174017 15

output:

773653506844739

result:

ok OK valid solution

Test #18:

score: 0
Accepted
time: 164ms
memory: 17368kb

input:

999999934158041 15

output:

460394886887112

result:

ok OK valid solution

Test #19:

score: 0
Accepted
time: 160ms
memory: 17320kb

input:

999870494845507 15

output:

323423996500080

result:

ok OK valid solution

Test #20:

score: 0
Accepted
time: 157ms
memory: 17452kb

input:

987500017287169 15

output:

881207504808157

result:

ok OK valid solution

Test #21:

score: 0
Accepted
time: 981ms
memory: 17284kb

input:

999869489774593 15

output:

-1

result:

ok OK no solution

Test #22:

score: 0
Accepted
time: 534ms
memory: 17320kb

input:

999999643058177 23

output:

89556549549344

result:

ok OK valid solution

Test #23:

score: 0
Accepted
time: 397ms
memory: 17316kb

input:

999029131455133 23

output:

912953334003060

result:

ok OK valid solution

Test #24:

score: 0
Accepted
time: 153ms
memory: 17380kb

input:

980573759207039 23

output:

-1

result:

ok OK no solution

Test #25:

score: 0
Accepted
time: 402ms
memory: 17444kb

input:

997380719651467 23

output:

255883246733265

result:

ok OK valid solution

Test #26:

score: 0
Accepted
time: 318ms
memory: 17400kb

input:

673383102728611 23

output:

-1

result:

ok OK no solution

Test #27:

score: 0
Accepted
time: 1164ms
memory: 17252kb

input:

997055929516033 23

output:

-1

result:

ok OK no solution

Test #28:

score: 0
Accepted
time: 158ms
memory: 17512kb

input:

3999999999999705089 15

output:

381067345616449405

result:

ok OK valid solution

Test #29:

score: 0
Accepted
time: 153ms
memory: 17316kb

input:

3999993153100322407 15

output:

1214657090453258166

result:

ok OK valid solution

Test #30:

score: 0
Accepted
time: 160ms
memory: 17464kb

input:

3999999979069450717 15

output:

1743498927959986936

result:

ok OK valid solution

Test #31:

score: 0
Accepted
time: 156ms
memory: 17512kb

input:

3999991341703927187 15

output:

1080709088574241881

result:

ok OK valid solution

Test #32:

score: 0
Accepted
time: 160ms
memory: 17448kb

input:

1641566238888296449 15

output:

1070525302444995667

result:

ok OK valid solution

Test #33:

score: 0
Accepted
time: 976ms
memory: 17296kb

input:

3999987196009414657 15

output:

-1

result:

ok OK no solution

Test #34:

score: 0
Accepted
time: 537ms
memory: 17460kb

input:

3999999999713738753 23

output:

31389787132760600

result:

ok OK valid solution

Test #35:

score: 0
Accepted
time: 611ms
memory: 17464kb

input:

3999977144498948549 23

output:

2198802854867146993

result:

ok OK valid solution

Test #36:

score: 0
Accepted
time: 253ms
memory: 17320kb

input:

3999999983264930527 23

output:

2212096408293331031

result:

ok OK valid solution

Test #37:

score: 0
Accepted
time: 660ms
memory: 17372kb

input:

3999867163212679501 23

output:

1272602077285424702

result:

ok OK valid solution

Test #38:

score: 0
Accepted
time: 566ms
memory: 17440kb

input:

2928465661120217089 23

output:

596640058846016531

result:

ok OK valid solution

Test #39:

score: 0
Accepted
time: 1162ms
memory: 17304kb

input:

3999790589313810433 23

output:

-1

result:

ok OK no solution

Test #40:

score: 0
Accepted
time: 335ms
memory: 17380kb

input:

65536 15

output:

-1

result:

ok OK no solution

Test #41:

score: 0
Accepted
time: 155ms
memory: 17424kb

input:

131072 15

output:

70115

result:

ok OK valid solution

Test #42:

score: 0
Accepted
time: 160ms
memory: 17316kb

input:

2305843009213693952 15

output:

1690609078868377601

result:

ok OK valid solution

Test #43:

score: 0
Accepted
time: 284ms
memory: 17396kb

input:

16777216 23

output:

-1

result:

ok OK no solution

Test #44:

score: 0
Accepted
time: 258ms
memory: 17436kb

input:

33554432 23

output:

16152779

result:

ok OK valid solution

Test #45:

score: 0
Accepted
time: 406ms
memory: 17452kb

input:

2305843009213693952 23

output:

1480880259527081985

result:

ok OK valid solution