結果

問題 No.1140 EXPotentiaLLL!
ユーザー pmpm
提出日時 2020-07-31 22:03:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,661 bytes
コンパイル時間 1,917 ms
コンパイル使用メモリ 177,748 KB
実行使用メモリ 73,932 KB
最終ジャッジ日時 2023-09-20 23:25:03
合計ジャッジ時間 11,807 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 1,183 ms
4,376 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 RE -
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

ll rui(ll a,ll b, ll mod){
     ll ans=1;
     while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
     return ans;
}

int main(){
    int T; cin >> T;
    rep(test, T){
        ll A, P; cin >> A >> P;
        if(is_prime(P)){
            vector<ll> v, memo(P); //memo:格納フラグ
            ll index = 1;
            while(1){
                ll num = rui(A, index, P);//Aのindex乗をPで割った余り
                if(memo[num])break;
                v.push_back(num);
                memo[num] = true;
                index++;
            }
            ll cnt = 0, siz = v.size();
            for(int i=P; i>1; i--){
                cnt = (cnt + i) % siz;
            }
            cnt = (cnt + siz - 1) % siz;
            cout << v[cnt] << ln;
        }else{
            cout << -1 << ln;
        }

    }
}
    
0