結果

問題 No.3023 Utility is Max?
ユーザー lam6er
提出日時 2025-04-16 00:25:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 795 bytes
コンパイル時間 1,951 ms
コンパイル使用メモリ 66,020 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-04-16 00:27:00
合計ジャッジ時間 2,200 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

int add(int a, int b) {
    while (b) {
        int carry = a & b;
        a = a ^ b;
        b = carry << (true);
    }
    return a;
}

int main() {
    int N;
    cin >> N;
    if (N < (true << true)) {
        cout << "NO" << endl;
    } else if (N == (true << true)) {
        cout << "YES" << endl;
    } else if ((N & true) == 0) {
        cout << "NO" << endl;
    } else {
        int i = add(true << true, true);
        bool is_prime = true;
        while (i < N) {
            if (N % i == 0) {
                is_prime = false;
                break;
            }
            i = add(i, true << true);
        }
        if (is_prime) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}
0