結果

問題 No.36 素数が嫌い!
ユーザー kkslucy1kkslucy1
提出日時 2018-03-11 03:51:09
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 741 bytes
コンパイル時間 1,181 ms
コンパイル使用メモリ 149,008 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 08:12:16
合計ジャッジ時間 16,730 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 16 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1,956 ms
4,380 KB
testcase_12 AC 2,604 ms
4,380 KB
testcase_13 AC 1,700 ms
4,376 KB
testcase_14 AC 9 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 90 ms
4,380 KB
testcase_20 AC 381 ms
4,376 KB
testcase_21 AC 625 ms
4,376 KB
testcase_22 AC 84 ms
4,376 KB
testcase_23 AC 37 ms
4,380 KB
testcase_24 AC 137 ms
4,380 KB
testcase_25 AC 503 ms
4,380 KB
testcase_26 AC 2,907 ms
4,376 KB
testcase_27 AC 125 ms
4,376 KB
testcase_28 AC 139 ms
4,376 KB
testcase_29 AC 25 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll gcd(ll n, ll m) {
	if (n > m) {
		ll copy = n;
		n = m;
		m = copy;
	}
	if (n == 0) {
		return m;
	}
	if (m%n == 0) {
		return n;
	}
	else {
		return gcd(m%n, n);
	}
}

int main() {
	ll n;
	cin >> n;
	if (n == 1) {
		cout << "NO" << endl;
		return 0;
	}

	int count = 0;
	queue<ll> q;
	q.push(n);
	do {
		n = q.front();q.pop();
		ll x = 2, y = 2, d = 1;
		while(d==1){
			x = (x*x + 1) % n;
			y = (y*y + 1) % n;
			y = (y*y + 1) % n;
			d = gcd(abs(x - y), n);
		}
		if (d < n) {
			q.push(n / d);
			q.push(d);
		}
		else{
			count++;
			if (count >= 3) {
				cout << "YES" << endl;
				return 0;
			}
		}
	} while (!q.empty());

	cout << "NO" << endl;


	return 0;
}
0