QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#480519#249. Miller Rabin 算法WrongAnswer_90#RE 123ms3964kbC++204.7kb2024-07-16 16:18:202024-07-16 16:18:21

Judging History

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

  • [2024-07-16 16:18:21]
  • 评测
  • 测评结果:RE
  • 用时:123ms
  • 内存:3964kb
  • [2024-07-16 16:18:20]
  • 提交

answer

#include<bits/stdc++.h>
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define ll long long
#define lll __int128
#define fi first
#define se second
#define e emplace
#define eb emplace_back
#define db double
#define ef emplace_front
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vp vector<pii>
#define mp make_pair

//#define LOCALJUDGE
 #define int ll
bool ST;
static const ll MOD=998244353,Phi=998244352,inv2=499122177,Root=3,iRoot=332748118;
static const ll inf=1073741823,INF=4557430888798830399;
static const ld eps=1e-9,pi=3.1415926535;
char in[1<<20],*p1=in,*p2=in;
using namespace std;
//#define getchar() (p1==p2&&(p2=(p1=in)+fread(in,1,1<<20,stdin),p1==p2)?EOF:*p1++)
struct tup{int x,y,z;tup(int X=0,int Y=0,int Z=0){x=X,y=Y,z=Z;}};
namespace FastIO
{
	template<typename T> inline void write(T x,char ch=' ')
	{
		if(is_same<char,T>::value)putchar(x);
		else
		{
			if(x<0)x=-x,putchar('-');
			static char st[25];int top=0;
			do{st[top++]=x%10+'0',x/=10;}while(x);
			while(top)putchar(st[--top]);
		}
		ch!='~'?putchar(ch):0;
	}
	inline void write(const char*x,char ch=' ')
	{
		for(int i=0;x[i]!='\0';++i)putchar(x[i]);
		ch!='~'?putchar(ch):0;
	}
	inline void read(char&s){do s=getchar();while(s=='\n'||s==' ');}
	inline void read(char s[])
	{
		int len=0;char st;
		do st=getchar();while(st=='\n'||st==' ');
		s[++len]=st,st=getchar();
		while(st!='\n'&&st!=' ')s[++len]=st,st=getchar();
		s[++len]='\0';
	}
	template<typename T> inline void read(T &s)
	{
		
		s=0;char ch=getchar();
		while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
		bool tf=(ch=='-')&&(ch=getchar());
		while((ch>='0')&&(ch<='9'))s=(s<<1)+(s<<3)+ch-'0',ch=getchar();
		s=(tf?-s:s);
	}
	template<typename T1,typename T2> inline void read(pair<T1,T2> &s){read(s.fi),read(s.se);}
	template<typename T,typename...Args> inline void write(T x,Args...args){write(x,'~'),write(args...);}
	template<typename T,typename...Args> inline void read(T&x,Args&...args){read(x),read(args...);}
}	
using namespace FastIO;
namespace MTool
{
	inline int Cadd(int a,int b){return (ll)a+b>=MOD?(ll)a+b-MOD:a+b;}
	inline int Cdel(int a,int b){return a-b<0?a-b+MOD:a-b;}
	inline int Cmul(int a,int b){return 1ll*a*b%MOD;}
	inline int sqr(int a){return 1ll*a*a%MOD;}
	inline void Madd(int&a,int b){a=((ll)a+b>=MOD?(ll)a+b-MOD:a+b);}
	inline void Mdel(int&a,int b){a=(a-b<0?a-b+MOD:a-b);}
	inline void Mmul(int&a,int b){a=1ll*a*b%MOD;}
	template<typename T> inline bool Mmax(T&a,T b){return a<b?a=b,1:0;}
	template<typename T> inline bool Mmin(T&a,T b){return a>b?a=b,1:0;}
	template<typename...Args> inline void Madd(int&a,int b,Args...args){Madd(a,b),Madd(a,args...);}
	template<typename...Args> inline void Mmul(int&a,int b,Args...args){Mmul(a,b),Mmul(a,args...);}
	template<typename...Args> inline void Mdel(int&a,int b,Args...args){Mdel(a,b),Mdel(a,args...);}
	template<typename...Args> inline int Cadd(int a,int b,Args...args){return Cadd(Cadd(a,b),args...);}
	template<typename...Args> inline int Cmul(int a,int b,Args...args){return Cmul(Cmul(a,b),args...);}
	template<typename...Args> inline int Cdel(int a,int b,Args...args){return Cdel(Cdel(a,b),args...);}
	template<typename...Args,typename T> inline bool Mmax(T&a,T b,Args...args){return Mmax(a,b)|Mmax(a,args...);}
	template<typename...Args,typename T> inline bool Mmin(T&a,T b,Args...args){return Mmin(a,b)|Mmin(a,args...);}
	inline int power(int x,int y){int s=1;for(;y;y>>=1,Mmul(x,x))if(y&1)Mmul(s,x);return s;}
}
using namespace MTool;
namespace WrongAnswer_90
{
	inline int mul(int x,int y,int z)
	{
		int a=x*((ld)y/z);
		int b=x*y-a*z;
		if(b<0)b+=z;
		if(b>=z)b-=z;
		return b; 
	}
	inline int power(int x,int y,int z)
	{
		int s=1;
		for(;y;y>>=1,x=mul(x,x,z))if(y&1)s=mul(s,x,z);
		return s;
	}
	mt19937 rnd(time(0));
	#define rd(l,r) ((l)+rnd()%((r)-(l)+1))
	inline bool chk(int n)
	{
		if(n<3||n%2==0)return n==2;
		int u=n-1,t=0;
		while(u%2==0)u/=2,++t;
		for(int i=0,s,a,v;i<10;++i)
		{
			a=rd(2,n-2),v=power(a,u,n);
			if(v==1)continue;
			for(s=0;s<t;++s)
			{
				if(v==n-1)break;
				v=mul(v,v,n);
			}
			if(s==t)return 0;
		}
		return 1;
	}
	inline void mian()
	{
		int n;
		while(cin>>n)
		{
			if(chk(n))puts("Y");
			else puts("N");
		}
	}
}
bool ED;
signed main()
{
//	#ifdef LOCALJUDGE
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
//	#endif
	double st=clock();
	WrongAnswer_90::mian();
	double ed=clock();
	#ifndef LOCALJUDGE
 	cerr<<endl;
	#endif
 	cerr<<"Time: "<<ed-st<<" ms\n";
	#ifdef LOCALJUDGE
 	cerr<<"     ";
	#endif
 	cerr<<"Memory: "<<abs(&ST-&ED)/1024.0/1024.0<<" MB\n";
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 123ms
memory: 3916kb

input:

996581938833575363
971646509461160317
773155992127361153
161603952726515268
540879144500456953
476831214764178553
784255927154201144
671096087619405061
805545190025269709
339546334309245137
337726347922962343
222956293307015293
809183111090275843
799050063298926344
691718101820598109
646220213113313...

output:

N
Y
Y
N
Y
Y
N
Y
Y
Y
Y
Y
Y
N
Y
N
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
N
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
N
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
N
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
N
Y
Y
Y
Y
Y
Y
Y
Y
N
Y
Y
N
Y
Y
Y
Y
Y
Y
Y
N
Y
Y
Y
Y
Y
Y
N
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
N
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
...

result:

ok 15000 lines

Test #2:

score: 0
Accepted
time: 72ms
memory: 3952kb

input:

292094793288448159
456918231632780153
52701684901220791
755430520029564023
202037556396478813
224321375550698537
953758266735232253
68668310674613297
730895589897264853
344428227893888993
521429852982590257
547788290718839273
332181270020381261
876010276438312333
906474115171090099
26200832832269134...

output:

N
N
Y
N
N
N
Y
N
Y
N
N
N
N
N
Y
N
Y
N
Y
Y
N
Y
Y
N
Y
N
Y
N
Y
N
Y
N
N
Y
N
Y
Y
Y
N
N
Y
N
Y
Y
Y
N
N
N
Y
N
N
Y
Y
N
N
N
N
Y
N
N
N
N
N
Y
Y
N
N
N
N
N
Y
N
Y
Y
Y
N
N
Y
N
Y
N
Y
N
N
Y
Y
N
N
N
N
Y
Y
N
Y
N
N
N
N
Y
Y
Y
N
Y
N
N
Y
N
N
Y
Y
Y
Y
Y
Y
Y
N
Y
N
N
N
Y
N
N
N
Y
N
Y
N
N
Y
N
N
N
Y
Y
Y
N
Y
Y
Y
N
Y
N
N
N
Y
N
Y
N
Y
...

result:

ok 15000 lines

Test #3:

score: 0
Accepted
time: 23ms
memory: 3936kb

input:

37686301288201
83818601792630641
73103085605161
146313732835525609
228087610722516540
343255869017446321
132173451449926849
461798530935794823
171613522570639321
746139393134794441
700705956080852569
186402586980996590
116687280644971921
439801455648601
608187424599317161
582838391995869241
29815648...

output:

N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
...

result:

ok 15000 lines

Test #4:

score: 0
Accepted
time: 19ms
memory: 3876kb

input:

37524996401344453
37525085907733993
37525091397104033
37525113078950641
37525124589187073
37525157683455557
37525199043948023
37525222109877577
37525226953298221
37525259363784397
37525364799923431
37525368433484977
37525385480376751
37525430877893551
37525482942628141
37525493960687851
375255005943...

output:

N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
...

result:

ok 15000 lines

Test #5:

score: 0
Accepted
time: 9ms
memory: 3924kb

input:

723245739019682401
723245866706340671
723246090945604561
723246352143004873
723246673219734913
723246738513052561
723247420392785287
723247522177775827
723247614067685477
723247698405894889
723247738890989761
723247925881512769
723248063125197301
723248128083366901
723248342755190227
723248614316335...

output:

N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
...

result:

ok 15000 lines

Test #6:

score: 0
Accepted
time: 20ms
memory: 3728kb

input:

971250844965384127
971250976411543033
971251162664749381
971251210275610351
971251238585098507
971251326624493501
971252030784923551
971252481632318471
971252499214789069
971252658880954081
971252709089043401
971252873506894229
971252918907625009
971253322904807251
971253706688543701
971254502032321...

output:

N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
...

result:

ok 15000 lines

Test #7:

score: 0
Accepted
time: 36ms
memory: 3928kb

input:

975097371418148287
975097379018158177
975098272399702153
975098914621552381
975098941416760309
975098970409909507
975099970219316947
975100563136905217
975100597682316769
975100651225654537
975100655012759497
975101039821060699
975101068247058001
975101132634439177
975101316642410317
975101700693099...

output:

N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
...

result:

ok 15000 lines

Test #8:

score: 0
Accepted
time: 8ms
memory: 3868kb

input:

978972814118579281
978972937612021549
978973242843932981
978974480980701913
978974489577710953
978974589631755737
978974652838559653
978974658221459201
978974733332204561
978974806453119673
978975038338417369
978975110530630693
978975222405387461
978975882983990251
978975989516617181
978976060640390...

output:

N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
...

result:

ok 15000 lines

Test #9:

score: 0
Accepted
time: 24ms
memory: 3932kb

input:

982815691526899273
982816054071509621
982817060169508141
982817430437283641
982817460181693753
982817461596064513
982817485076790919
982817582130019357
982817899620348031
982818063245540321
982818404515863917
982818922902003769
982818962551574209
982819103882371901
982819366081816363
982819443060395...

output:

N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
...

result:

ok 15000 lines

Test #10:

score: 0
Accepted
time: 20ms
memory: 3936kb

input:

986654079350625311
986654424121995397
986654475796632901
986654694060905039
986655094343402881
986655789507565913
986655796720217821
986655894969286081
986656845736427113
986656893630525577
986656899715648481
986656967546105017
986656981419420361
986657020079418001
986657751538639291
986657836955081...

output:

N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
...

result:

ok 15000 lines

Test #11:

score: 0
Accepted
time: 25ms
memory: 3888kb

input:

990506396486037061
990506434942654297
990506583343038737
990506633090169007
990506821692002869
990507338152078781
990507642857678513
990509266701009901
990509413103916829
990509672526354901
990509839077929941
990509905448558701
990509948480836033
990509955041980081
990510051552449809
990510327054720...

output:

N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
...

result:

ok 15000 lines

Test #12:

score: 0
Accepted
time: 24ms
memory: 3928kb

input:

994436482283245501
994436834643112771
994437438334877633
994438185016980251
994438518667870537
994438572113239849
994439331088447063
994440181755753253
994440412354207381
994440486375543241
994440532681357841
994440572217582901
994440737643657637
994441422312035101
994441492070689121
994441676618381...

output:

N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
...

result:

ok 15000 lines

Test #13:

score: 0
Accepted
time: 9ms
memory: 3964kb

input:

998325346159240081
998325547301434393
998326073288529899
998326268408182393
998326321136886799
998326462535387389
998327440063121761
998327468968116311
998327968547706001
998328232689759721
998328353036363983
998328398641461907
998328773289179851
998329620625002751
998329775152828861
998329853754818...

output:

N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
...

result:

ok 6507 lines

Test #14:

score: -100
Runtime Error

input:

100052803951001600
105728860800000000
893853530276283200
6455400775964240
685235886664718720
793482962376918720
758221361453121056
37589855997724840
1128108118059
895139368646464000
483432966915053800
237004108121200000
22178
645282657277920000
813367395538094000
1136069149644000
281785329587500000
...

output:

N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
Y
N
N
N
N
N
N
N
Y
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
...

result: