結果

問題 No.2795 Perfect Number
ユーザー kentikenti
提出日時 2024-06-28 21:39:41
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 611 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 80,908 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-28 21:39:46
合計ジャッジ時間 1,976 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
typedef long long ll;

ll N;

int main() {
    cin >> N;
    if (N == 1) {
        cout << "No" << endl;
        return 0;
    }
    int ct1 = 0, ct2 = 0;
    while (N % 2 == 0) {
        N /= 2;
        ct1++;
    }
    ll m = N;
    N++;
    while (N % 2 == 0) {
        N /= 2;
        ct2++;
    }
    if (ct1 + 1 != ct2 || N != 1) {
        cout << "No" << endl;
        return 0;
    }
    for (ll i = 2; i * i <= m; i++) {
        if (m % i == 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}
0