結果

問題 No.36 素数が嫌い!
ユーザー kkslucy1kkslucy1
提出日時 2018-03-11 03:16:11
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 695 bytes
コンパイル時間 1,405 ms
コンパイル使用メモリ 163,468 KB
実行使用メモリ 14,024 KB
最終ジャッジ日時 2024-04-23 00:52:44
合計ジャッジ時間 17,005 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 14 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 5 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 1,744 ms
6,944 KB
testcase_12 AC 2,336 ms
6,944 KB
testcase_13 AC 1,511 ms
6,944 KB
testcase_14 AC 8 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

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;

	int count = 0;

	ll d;
	queue<ll> q;
	q.push(n);
	do {
		n = q.front();
		q.pop();
		ll x = 2;
		ll y = 2;
		do {
			x = (x*x + 1) % n;
			y = (y*y + 1) % n;
			y = (y*y + 1) % n;
			d = gcd(abs(x - y), n);
		} while (d == 1);
		if (d < n) {
			q.push(d);
			q.push(n / d);
			count++;
		}
	} while (!q.empty());
	count++;

	if (count >= 3) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}



	return 0;
}
0