結果
| 問題 |
No.981 一般冪乗根
|
| ユーザー |
|
| 提出日時 | 2020-02-08 16:32:05 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,099 bytes |
| コンパイル時間 | 1,979 ms |
| コンパイル使用メモリ | 177,056 KB |
| 実行使用メモリ | 8,832 KB |
| 最終ジャッジ日時 | 2024-10-09 14:52:08 |
| 合計ジャッジ時間 | 81,399 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 20 TLE * 7 -- * 17 |
ソースコード
#include<bits/stdc++.h>
#define XX first
#define YY second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;
#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
int T;
using ULL = unsigned long long;
ULL xorshift(void) {
static ULL x = 123456789;
static ULL y = 362436069;
static ULL z = 521288629;
static ULL w = 88675123;
ULL t;
t = x ^ (x << 11);
x = y; y = z; z = w;
return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}
LL mypow(LL base, LL exp, LL mod) {
if (exp == 0) return 1;
LL res = mypow(base*base%mod, exp/2, mod);
if (exp%2) res = res*base%mod;
return res;
}
inline ll modinv(ll a, ll m){
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return (u % m + m) % m;
}
void Solve() {
LL p, k, a;
cin >> p >> k >> a;
LL n = 1;
while (n*n*10 < p) n++;
//n *= 3;
//n = LL(1e6);
unordered_map<LL, LL> us;
rep(i, n) {
LL t = 1 + xorshift() % (p-1);
LL tk = mypow(t, k, p);
if (tk == a) {
cout << t << endl;
return;
}
us[modinv(tk, p)*a%p] = t;
if (us.count(tk)) {
LL ans = us[tk] * t % p;
//assert(mypow(ans, k, p) == a);
cout << ans << endl;
return;
}
}
cout << "-1\n";
}
signed main(){
ios_base::sync_with_stdio(false);
cout<<fixed<<setprecision(0);
cin >> T;
while (T--) {
Solve();
}
}