結果

問題 No.3493 等比数列の和の素因数
コンテスト
ユーザー GOTKAKO
提出日時 2026-04-03 23:19:56
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
OLE  
実行時間 -
コード長 712 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,670 ms
コンパイル使用メモリ 209,820 KB
実行使用メモリ 11,556 KB
最終ジャッジ日時 2026-04-03 23:20:38
合計ジャッジ時間 8,424 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other OLE * 1 -- * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

bool check(long long N,long long P){

    for(long long x=1; x<P; x++){
        long long v = 0,p = 1;
        for(int i=0; i<=N; i++) v += p,p = p*x%P;
        if(v%P == 0) return true;
    }
    return false;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while(true){
    long long N,P; cin >> N >> P;
    if(check(N,P)) cout << "Yes\n";
    else cout << "No\n";

    if(N == 0) cout << "No\n";
    else if(P == 2){
        if(N%2) cout << "Yes\n";
        else cout << "No\n";
    }
    else if((N+1)%(P-1) == 0) cout << "Yes\n";
    else if((P-1)%(N+1) == 0) cout << "Yes\n";
    else cout << "No\n";
    cout << endl;
    }
}
0