結果

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define MAX 10000010
bool prime[MAX];

typedef unsigned long long ull;

void sieve() {
  fill(prime, prime+MAX, true);
  prime[0] = prime[1] = false;
  
  for(ull i=2 ; i*i<MAX ; i++){
    if(prime[i]){
      for(ull j=i*i ; j<MAX ; j+=i){
	prime[j] = false;
      }
    }
  }
}
  bool isPrime(ull a) { for(ull i=2; i*i <=a; i++) if(a%i == 0) return false; return true; }

int main() {

  sieve();
  ull N; cin >> N;
  
  if(N == 1) { cout << "NO\n"; return 0; }
  
  int cnt = 0;
  ull K = N;
  for(ull i=2; i*i<=K; i++) {
    if(prime[i]) {
      while(N % i == 0) {
	N /= i;
	cnt ++;
      }
    }
  }
  
  if(N > 1) {
    cnt ++;
  }
  
  if(cnt > 2) cout << "YES\n";
  else cout << "NO\n";
  
  return 0;
}
0