結果
| 問題 | 
                            No.36 素数が嫌い!
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-02-10 03:28:00 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,815 bytes | 
| コンパイル時間 | 1,350 ms | 
| コンパイル使用メモリ | 160,444 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-21 22:04:11 | 
| 合計ジャッジ時間 | 2,315 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 25 WA * 1 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
typedef long long ll;
long long modmul(long long a, long long b, long long mod) {
	long long ret = 0;
	for (; b > 0; a = a * 2 % mod, b /= 2) if (b & 1) ret = (ret + a) % mod;
	return ret;
}
long long modpow(long long a, long long b, long long mod) {
	long long ret = 1;
	for (; b > 0; a = modmul(a, a, mod), b /= 2) if (b & 1) ret = modmul(ret, a, mod);
	return ret;
}
bool isPrime(long long n) {
	if (n <= 1 || (n > 2 && n % 2 == 0)) return false;
	const int bases[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37 };
	ll d = n - 1, s = 0;
	while (d % 2 == 0) s++, d /= 2;
	auto suspect = [&](ll a) {
		long long x = modpow(a, d, n);
		if (x == 1) return true;
		for (int r = 0; r < s; r++, x = modmul(x, x, n)) if (x == n - 1) return true;
		return false;
	};
	for (int base : bases) if (base < n && !suspect(base)) return false;
	return true;
}
long long rho(long long n) {
	for (long long c = 1; c < n; c++) if (c != n - 2) {
		long long x = 2, y = 2, d = 1;
		auto f = [&](long long x) { return (modmul(x, x, n) + c) % n; };
		while (d == 1) x = f(x), y = f(f(y)), d = __gcd(abs(x - y), n);
		if (d != n) return d;
	}
	return -1;
}
bool solve() {
	ll n;
	cin >> n;
	if (n == 1) return false;
	if (isPrime(n)) return false;
	ll r = rho(n);
	if (isPrime(r)) return !isPrime(n / r);
	return true;
}
int main() {
	cout << (solve() ? "YES" : "NO") << endl;
	return 0;
}