結果
| 問題 |
No.192 合成数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-05-23 08:53:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,553 bytes |
| コンパイル時間 | 674 ms |
| コンパイル使用メモリ | 82,424 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-20 13:01:55 |
| 合計ジャッジ時間 | 1,953 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 24 WA * 1 |
ソースコード
#include <iostream> //cin, cout
#include <vector> //vector
#include <algorithm> //sort,min,max,count
#include <string> //string,getline, to_string
#include <cstdlib> //abs(int)
#include <utility> //swap, pair
#include <deque> //deque
#include <climits> //INT_MAX
#include <bitset> //bitset
#include <cmath> //sqrt, ceil. M_PI, pow, sin
#include <ios> //fixed
#include <iomanip> //setprecision
#include <sstream> //stringstream
using namespace std;
inline bool JudgePrimeNumber(const long long int a) {
//素数か判定する
if (a < 2) { return false; }
if (a == 2) { return true; }
if (a % 2 == 0) { return false; }
for (long long int i = 3; i <= a / i; i += 2) {
if (a % i == 0) {
return false;
}
}
return true;
}
inline bool JudgeMultipleOfThree(const long long int n) {
//3の倍数か判定する
long long int temp = n;
long long int sum = 0;
while (temp > 0) {
sum += n % 10;
temp /= 10;
}
if (sum % 3 == 0) { return true; }
else { return false; }
}
inline bool JudgeCompositeNumber(const long long int a) {
//合成数か判定する
if (a < 4) { return false; }
if (a % 2 == 0) { return true; }
if (a < 10) {
if (a == 9) { return true; }
else { return false; }
}
else {
if (a % 10 == 5) { return true; }
if (JudgeMultipleOfThree(a)) { return true; }
if (!JudgePrimeNumber(a)) { return true; }
}
return false;
}
int main() {
int N;
cin >> N;
for (int i = N - 100; i <= N + 100; i++) {
if (JudgeCompositeNumber(i)) {
cout << i << endl;
return 0;
}
}
return 0;
}