結果
| 問題 |
No.308 素数は通れません
|
| コンテスト | |
| ユーザー |
saytakaPC
|
| 提出日時 | 2015-12-01 14:04:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,204 bytes |
| コンパイル時間 | 1,273 ms |
| コンパイル使用メモリ | 160,796 KB |
| 実行使用メモリ | 13,884 KB |
| 最終ジャッジ日時 | 2024-09-14 05:16:53 |
| 合計ジャッジ時間 | 6,476 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 70 WA * 20 TLE * 1 -- * 16 |
ソースコード
#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 to_i(string s){
ll k=1,res=0;
for(int i=s.size()-1;i>=0;i--){
res+=k*(s[i]-'0');
k*=10;
}
return res;
}
bool is_prime(ll n){
for(ll i=2;i*i<=n;i++){
if(n%i==0)return false;
}
return true;
}
int main(){
string 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.size()>=15){
cout<<8<<endl;
}
ll n=to_i(s);
if(n%8!=1)cout<<8<<endl;
else if(!is_prime(n-8))cout<<8<<endl;
else cout<<14<<endl;
return 0;
}
saytakaPC