結果

問題 No.36 素数が嫌い!
コンテスト
ユーザー Rumain831
提出日時 2026-07-30 05:10:01
言語 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  
実行時間 96 ms / 5,000 ms
+ 683µs
コード長 856 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,790 ms
コンパイル使用メモリ 170,616 KB
実行使用メモリ 46,844 KB
最終ジャッジ日時 2026-07-30 05:10:23
合計ジャッジ時間 6,955 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

//Tags: 整数, 素数
//答えがNOになるのは、n=1 or nが素数 or n=pq(p, qは相異なる素数) のとき
int main(void){
  ll n; cin >> n;
  if(n==1){
    cout << "NO" << endl; return 0;
  }
  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(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