結果

問題 No.36 素数が嫌い!
ユーザー Mcpu3Mcpu3
提出日時 2019-03-16 13:33:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 141 ms / 5,000 ms
コード長 854 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 70,928 KB
実行使用メモリ 4,608 KB
最終ジャッジ日時 2023-09-14 15:13:57
合計ジャッジ時間 3,742 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
4,376 KB
testcase_01 AC 40 ms
4,416 KB
testcase_02 AC 38 ms
4,380 KB
testcase_03 AC 38 ms
4,376 KB
testcase_04 AC 39 ms
4,380 KB
testcase_05 AC 40 ms
4,384 KB
testcase_06 AC 39 ms
4,376 KB
testcase_07 AC 39 ms
4,380 KB
testcase_08 AC 39 ms
4,384 KB
testcase_09 AC 38 ms
4,400 KB
testcase_10 AC 38 ms
4,380 KB
testcase_11 AC 72 ms
4,376 KB
testcase_12 AC 141 ms
4,380 KB
testcase_13 AC 141 ms
4,428 KB
testcase_14 AC 40 ms
4,608 KB
testcase_15 AC 39 ms
4,376 KB
testcase_16 AC 38 ms
4,376 KB
testcase_17 AC 38 ms
4,400 KB
testcase_18 AC 38 ms
4,424 KB
testcase_19 AC 39 ms
4,424 KB
testcase_20 AC 41 ms
4,380 KB
testcase_21 AC 38 ms
4,396 KB
testcase_22 AC 38 ms
4,380 KB
testcase_23 AC 38 ms
4,384 KB
testcase_24 AC 52 ms
4,380 KB
testcase_25 AC 39 ms
4,376 KB
testcase_26 AC 135 ms
4,380 KB
testcase_27 AC 129 ms
4,428 KB
testcase_28 AC 133 ms
4,472 KB
testcase_29 AC 138 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

//	vector
struct theSieveOfEratosThenes {
	vector<bool> prm;

	theSieveOfEratosThenes(int n) {
		prm = vector<bool>(n + 1, true);
		prm[0] = prm[1] = false;
		for (int i = 2; i * i <= n; ++i) {
			if (prm[i]) {
				for (int j = 2 * i; j <= n; j += i) prm[j] = false;
			}
		}
	}

	bool isPrime(int a) {
		return prm[a];
	}
};

template<typename T>
bool trialDivision(T a) {
	if (a == 1) return false;
	T i;
	for (i = 2; i * i <= a; ++i) {
		if (a % i == 0) break;
	}
	if (a < i * i) return true;
	return false;
}

int main() {
	long N, i;
	cin >> N;
	theSieveOfEratosThenes tsoet(10000000);
	for (i = 2; i * i <= N; ++i) {
		if (N % i == 0 && (!tsoet.isPrime(i) || !trialDivision(N / i))) break;
	}
	if (N < i * i) cout << "NO";
	else cout << "YES";
}
0