結果

問題 No.36 素数が嫌い!
ユーザー tkr987
提出日時 2019-08-08 19:14:12
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 153 ms / 5,000 ms
コード長 1,018 bytes
コンパイル時間 1,505 ms
コンパイル使用メモリ 166,476 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-18 20:55:38
合計ジャッジ時間 3,008 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)				// repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)			// repeat reverse

#endif

bool IsPrime(ll num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

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

	if (n == 1 || IsPrime(n))
	{
		cout << "NO" << endl;
		return 0;
	}

	ll lc = (ll)sqrt(n) + 1;
	rep(i, 2, lc)
	{
		if (n % i == 0)
		{
			if (!IsPrime(n / i))
			{
				cout << "YES" << endl;
				return 0;
			}
		}
	}

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