結果
問題 |
No.1140 EXPotentiaLLL!
|
ユーザー |
![]() |
提出日時 | 2020-07-31 22:44:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,291 bytes |
コンパイル時間 | 2,214 ms |
コンパイル使用メモリ | 194,856 KB |
最終ジャッジ日時 | 2025-01-12 11:01:26 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 WA * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:57:17: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=] 57 | scanf("%d%d",&a,&p); | ~^ ~~ | | | | int* long long int* | %lld main.cpp:57:19: warning: format ‘%d’ expects argument of type ‘int*’, but argument 3 has type ‘long long int*’ [-Wformat=] 57 | scanf("%d%d",&a,&p); | ~^ ~~ | | | | int* long long int* | %lld main.cpp:57:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 57 | scanf("%d%d",&a,&p); | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; struct Miller{ const vector<long long> v = { 2 , 7 , 61 }; // < 4,759,123,141 // x^k (mod m) long long modpow( long long x, long long k, long long m ){ long long res = 1; while( k ){ if( k & 1 ){ res = res * x % m; } k /= 2; x = x * x % m; } return res; } // check if n is prime bool check( long long n ){ if( n < 2 ){ return false; } long long d = n - 1; long long s = 0; while( d % 2 == 0 ){ d /= 2; s++; } for( long long a : v ){ if( a == n ){ return true; } if( modpow( a , d , n ) != 1 ){ bool ok = true; for( long long r = 0; r < s; r++ ){ if( modpow( a, d * (1LL << r), n ) == n-1 ){ ok = false; break; } } if( ok ){ return false; } } } return true; } }; Miller miller; int main(){ int n; cin >> n; for (int i = 0; i < n; i++){ long long a; long long p; scanf("%d%d",&a,&p); int ans; if (miller.check((int)p)) { ans = 1; if (gcd(a, p) == p) ans = 0; } else ans = -1; printf("%d\n",ans); } }