結果

問題 No.308 素数は通れません
ユーザー saytakaPC
提出日時 2015-12-01 22:12:53
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,359 bytes
コンパイル時間 1,352 ms
コンパイル使用メモリ 159,584 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-14 06:40:41
合計ジャッジ時間 3,636 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 102 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
int INF=1e9;
int MOD=1000000007;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
double EPS = 1e-10;
ll pow1(ll base,ll power,ll mod){
	ll result=1;
	while(power>0){
		if(power&1==1)result=(result*base)%mod;
		base=(base*base)%mod;
		power>>=1;
	}
	return result;
}
bool is_prime(ll n){
	if(n==2)return true;
	if(n==1||n&1==0)return false;
	ll d=n-1;
	while(d&1==0)d>>=1;
	REP(i,100){
		ll a=rand()%(n-2)+1;
		ll t=d;
		ll y=pow1(a,t,n);
		while(t!=n-1&&y!=1&&y!=n-1){
			y=(y*y)%n;
			y<<=1;
		}
		if(y!=n-1&&y&1==0)return false;
	}
	return true;
}
int main(){
	srand((unsigned)time(NULL));
	long long s;
	cin>>s;
	if(s==1){
		cout<<1<<endl;
		return 0;
	}
	if(s==4){
		cout<<3<<endl;
		return 0;
	}
	if(s==6){
		cout<<5<<endl;
		return 0;
	}
	if(s==8||s==9||s==10||s==15||s==16||s==22){
		cout<<7<<endl;
		return 0;
	}
	if(s==12){
		cout<<11<<endl;
		return 0;
	}
	if(s==14||s==15||s==16){
		cout<<13<<endl;
		return 0;
	}
	if(s==20||s==21||s==22){
		cout<<19<<endl;
		return 0;
	}
	if(s==24||s==25){
		cout<<23<<endl;
		return 0;
	}
	if(s%(ll)8!=1)cout<<8<<endl;
	else if(!is_prime(s-(ll)8))cout<<8<<endl;
	else cout<<14<<endl;
	return 0;
}
0