QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#497769#249. Miller Rabin 算法hhy0613Compile Error//C++14921b2024-07-29 17:35:492024-07-29 17:35:51

Judging History

This is the latest submission verdict.

  • [2024-07-29 17:35:51]
  • Judged
  • [2024-07-29 17:35:49]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const __int128 o=1;
long long qpow(long long a,long long b,long long mod){
	long long ans=1;
	while(b>0){
		if(b&1) ans=o*ans*a%mod;
		b>>=1;
		a=o*a*a%mod;
	}
	return ans;
}
namespace MillerRabin{
	const int K=9,arr[K]={2,3,5,7,11,13,17,19,23,29};
	bool IsPrime(long long p){
		for(int a:arr){
			if(p%a==0) return (p==a);
			if(qpow(a,p-1,p)!=1) return false;
			long long r=p-1;
			int d=0;
			while(r%2==0){
				++d;
				r>>=1;
			}
			if(qpow(a,r,p)==1) continue;
			long long now=qpow(a,r,p);
			for(int i=0;i<=d;++i){
				if(now==p-1) break;
				if(i==d) return false;
				now=o*now*now%p;
			}
		}
		return true;
	}
}
using MillerRabin::IsPrime;
int main(){
	ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
	long long x;
	while(cin >> x){
		if(IsPrime(x)) cout << "Y\n";
		else cout << "N\n";
	}
	return 0;
}

詳細信息

answer.code:14:56: error: too many initializers for ‘const int [9]’
   14 |         const int K=9,arr[K]={2,3,5,7,11,13,17,19,23,29};
      |                                                        ^