結果

問題 No.8023 素数判定するだけ
ユーザー a01sa01to
提出日時 2025-06-23 00:49:28
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 387 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 78,272 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-06-23 00:49:35
合計ジャッジ時間 6,568 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

constexpr int Zero = !'a', One = !Zero;

inline int add_one(int x) {
  int t = One;
  while (x & t) {
    x ^= t;
    t <<= One;
  }
  x ^= t;
  return x;
}

int main() {
  int n;
  cin >> n;
  bool p = (n != One);
  for (int i = One << One; i < n; i = add_one(i)) {
    if (n % i == Zero) p = false;
  }
  cout << (p ? "YES" : "NO") << '\n';
}
0