結果

問題 No.36 素数が嫌い!
ユーザー Klay
提出日時 2017-04-27 02:07:08
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 636 bytes
コンパイル時間 566 ms
コンパイル使用メモリ 59,372 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-13 13:06:23
合計ジャッジ時間 1,923 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

bool is_prime(unsigned long long n)
{
	switch(n)
	{
		case 0:
		case 1: return true;
		case 2: 
		case 3: return true;
	}

	if(n % 2 == 0) return false;
    
	if(n % 3 == 0) return false;

	if(n % 6 != 1 && n % 6 != 5) return false;

	for(unsigned long long i = 5; i * i <= n; i += 6)
	{
		if(n % i == 0) return false;
		if(n % (i + 2) == 0) return false;
	}

	return true;
}

int main(void)
{
	unsigned long long N;
	
	std::cin >> N;	
	
	if(is_prime(N))
	{
		std::cout << "NO" << std::endl;
	}
	else
	{
		std::cout << "YES" << std::endl;
	}
	
	return 0;
}
0