結果

問題 No.1140 EXPotentiaLLL!
ユーザー Sooh31Sooh31
提出日時 2020-07-31 21:50:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 985 bytes
コンパイル時間 1,978 ms
コンパイル使用メモリ 199,660 KB
実行使用メモリ 46,864 KB
最終ジャッジ日時 2023-09-20 22:56:06
合計ジャッジ時間 8,538 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 1,168 ms
4,376 KB
testcase_02 RE -
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:34:21: 警告: ‘tmp’ may be used uninitialized [-Wmaybe-uninitialized]
   34 |                 cnt = cnt * i % tmp;
      |                 ~~~~^~~~~~~~~~~~~~~
main.cpp:22:17: 備考: ‘tmp’ はここで定義されています
   22 |             int tmp;
      |                 ^~~

ソースコード

diff #

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

const int MAX = 5e6 + 7;

ll cr[MAX];

bool is_prime(ll p){
    for(int i = 2; i * i <= p; i++){
        if(p % i == 0) return false;
    }
    return true;
}
int main(){
    int t; cin >> t;
    while(t--){
        ll a, p; cin >> a >> p;
        if(is_prime(p)){
            ll fact[p+1];
            fact[1] = a % p;
            int tmp;
            for(int i = 2; i <= p; i++){
                fact[i] = fact[i-1] * a % p;
                //cout << i << " " <<  fact[i] << endl;
                if(fact[i] == fact[1]){
                    tmp = i - 1;
                    break;
                }
            }
            //cout << tmp << endl;
            int cnt = 1;
            for(int i = 2; i <= p; i++){
                cnt = cnt * i % tmp;
            }
            if(cnt == 0) cnt = tmp;
            cout << fact[cnt] << endl;
        }
        else{
            cout << -1 << endl;
        }
    }
}
0