結果

問題 No.36 素数が嫌い!
ユーザー vain0
提出日時 2015-07-22 10:42:16
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 100 ms / 5,000 ms
コード長 802 bytes
コンパイル時間 728 ms
コンパイル使用メモリ 72,304 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-27 00:21:07
合計ジャッジ時間 1,876 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
using ll = long long;
#define rep(_I, _N) for(int _I = 0; (_I) < (_N); ++ (_I))

map<ll, ll> factorize(ll n)
{
	map<ll, ll> t;

	int m = n;
	for ( ll i = 2; i * i <= n; ++i ) {
		while ( (n % i) == 0 ) {
			t[n] ++;
			n /= i;
		}
	}
	if ( n != 1 ) { t[n] ++; }

	return move(t);
}

bool check(map<ll, ll> const& facts)
{
	switch ( facts.size() ) {
		case 0:
			return false;
		case 1:
		case 2: {
			int pops = 0;
			for ( auto&& kv: facts ) {
				pops += kv.second;
			}
			return pops >= 3;
		}
		default:
			return true;
	}
}

int main()
{
	ll n;
	cin >> n;

	auto facts = factorize(n);
	cout << (check(facts) ? "YES" : "NO") << endl;
	return 0;
}
0