結果

問題 No.36 素数が嫌い!
ユーザー hanorverhanorver
提出日時 2016-05-03 16:01:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 949 bytes
コンパイル時間 746 ms
コンパイル使用メモリ 75,860 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 10:17:46
合計ジャッジ時間 2,137 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<map>

// n を素因数分解し、素因数を返す
std::map<long long, int> pf(long long n) {
	// <素数,出現回数>
	std::map<long long, int> m;
	while (n % 2 == 0) {
		m[2]++;
		n /= 2;
	}

	while (n % 3 == 0) {
		m[3]++;
		n /= 3;
	}


	for (long long i = 6; i * i <= n; i += 6) {
		while ((i - 1) % n == 0) {
			m[i - 1]++;
			n /= (i - 1);
		}
		while ((i + 1) % n == 0) {
			m[i - 1]++;
			n /= (i - 1);
		}
	}

	return m;
}


int main() {
	long long n;

	std::cin >> n;

	std::map<long long, int> prime_factors = pf(n);

	long long num = 1;
	for (auto i = prime_factors.begin(); i != prime_factors.end(); i++) {
		if (i->second > 1) {
			if (i->first * i->first != n) {
				std::cout << "YES" << std::endl;
				return 0;
			}
		} else {
			num *= i->first;
		}
		if (num > 2 && num % 2 != 1 && num != n) {
			std::cout << "YES" << std::endl;
			return 0;
		}
	}

	std::cout << "NO" << std::endl;
	return 0;
}
0