結果

問題 No.36 素数が嫌い!
ユーザー DialBird
提出日時 2016-11-23 09:23:02
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 611 bytes
コンパイル時間 483 ms
コンパイル使用メモリ 64,908 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-27 10:18:34
合計ジャッジ時間 3,068 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 23 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

const long long MAX_N = 100000000000000;
long long N;
vector<bool> nonprimes(10000001);

void get_nonprimes(int n){
  for (int i=2;i<=n;i++) {
    if (nonprimes[i] == 0) {
      for (int j=0;i*(j+2)<=n;j++) {
        nonprimes[i*(j+2)] = 1;
      }
    }
  }
}

int main(){
  string result = "NO";
  cin>>N; 
  get_nonprimes((int)sqrt(N));
  
  for (auto it=nonprimes.begin();it!=nonprimes.end();it++) {
    if (*it && N % distance(nonprimes.begin(), it) == 0) {
      result = "YES"; 
      break;
    }
  }
  cout<<result<<endl;
}
0