結果

問題 No.36 素数が嫌い!
コンテスト
ユーザー Rumain831
提出日時 2026-07-30 04:55:49
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.90.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 104 ms / 5,000 ms
+ 708µs
コード長 713 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,584 ms
コンパイル使用メモリ 177,220 KB
実行使用メモリ 46,844 KB
最終ジャッジ日時 2026-07-30 04:55:58
合計ジャッジ時間 6,233 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

int main(void){
  ll n; cin >> n;
  int nn=1e7+1;
  vector<int> yakusu(nn+1, -1), prime;
  for(int i=2; i<=nn; i++){
    if(yakusu[i]!=-1) continue;
    int copy=i;
    prime.push_back(i);
    while(copy<=nn){
      if(yakusu[copy]==-1) yakusu[copy]=i;
      copy+=i;
    }
  } 
  auto judge=[&](ll x){
    for(auto p:prime){
      if((ll)p*p>x) break;
      if(x%p==0) return false;
    }
    return true;
  };
  if(n==1||judge(n)){
    cout << "NO" << endl; return 0;
  }
  for(auto p:prime){
    if(p>n) break;
    if(n%p) continue;
    cout << (judge(n/p)?"NO":"YES") << endl;
    return 0;
  }
  return 0; 
}
0