結果
問題 | No.312 置換処理 |
ユーザー |
|
提出日時 | 2018-06-08 13:57:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 928 bytes |
コンパイル時間 | 546 ms |
コンパイル使用メモリ | 69,500 KB |
実行使用メモリ | 13,756 KB |
最終ジャッジ日時 | 2024-06-30 10:39:29 |
合計ジャッジ時間 | 4,060 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 WA * 4 TLE * 1 -- * 36 |
ソースコード
#include <iostream> #include <math.h> using namespace std; typedef long long LL; using namespace std; bool IsPrime(LL num)//素数であるか? { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; // 偶数はあらかじめ除く double sqrtNum = sqrt((double)num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { // 素数ではない return false; } } // 素数である return true; } LL getV(LL N) { if (N%2==0){ return 2; } if (N%3==0){ return 3; } if (IsPrime(N)){ return N; } LL i=5; bool flag=true; while(i<=N){ if (N%i==0){ return i; } if (!flag){ i+=2; }else{ i+=4; } flag=!flag; } return 0; } int main(int argc, char* argv[]) { LL N; cin>>N; if (N%2==0){ cout<<2*getV(N/2)<<endl; }else{ cout<<getV(N)<<endl; } return 0; }