結果
問題 | No.984 Inversion |
ユーザー |
![]() |
提出日時 | 2020-02-11 14:57:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 658 bytes |
コンパイル時間 | 872 ms |
コンパイル使用メモリ | 79,864 KB |
最終ジャッジ日時 | 2025-01-08 23:38:35 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 24 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; ll pw(ll a, ll x,ll mod){ ll ret = 1; while(x){ while(!(x&1)){ (a *= a) %= mod; x /= 2; } (ret *= a) %= mod; x--; } return ret; } vector<ll> v; int main(){ ll i,p,n; cin >> p >> n; for(i=1;i*i<=p - 1;i++){ if((p - 1)%i==0){ v.push_back(i); if(i*i!=p-1){ v.push_back((p - 1)/i); } } } if(n==1){ cout << 0 << endl; return 0; } sort(v.begin(),v.end()); ll j = -1; for(i=0;i<v.size();i++){ if(v[i]==1) continue; if(pw(n,v[i],p)==1){ j = v[i]; break; } } int x = (p - 1)/j; cout << (x&1) << endl; }