結果

問題 No.36 素数が嫌い!
ユーザー myanta
提出日時 2017-05-01 01:44:31
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 78 ms / 5,000 ms
コード長 623 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 23,552 KB
実行使用メモリ 11,248 KB
最終ジャッジ日時 2024-06-27 01:05:04
合計ジャッジ時間 2,771 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>


typedef long long ll;


#define SIEVE_MAX 10000000

char sieve[SIEVE_MAX+1];

void sieve_init(void)
{
	int i, j;

	sieve[0]=sieve[1]=1;

	for(i=4;i<=SIEVE_MAX;i+=2) sieve[i]=1;

	for(i=3;i<=SIEVE_MAX;i+=2)
	{
		if(sieve[i]) continue;
		for(j=i*3;j<=SIEVE_MAX;j+=i*2)
		{
			sieve[j]=1;
		}
	}
}


int solve(ll x)
{
	ll i;
	int c=0;

	for(i=2;i*i<=x;i++)
	{
		if(sieve[i]) continue;
		for(;x%i==0;x/=i)
		{
			c++;
			if(c>=3) return 1;
		}
	}
	if(x>1) c++;

	return c>=3;
}


int main(void)
{
	ll n;

	sieve_init();
	while(scanf("%lld", &n)==1)
	{
		printf("%s\n", solve(n)?"YES":"NO");
	}

	return 0;
}
0