結果
問題 |
No.1140 EXPotentiaLLL!
|
ユーザー |
![]() |
提出日時 | 2020-07-31 22:16:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,059 bytes |
コンパイル時間 | 2,396 ms |
コンパイル使用メモリ | 194,780 KB |
最終ジャッジ日時 | 2025-01-12 10:30:06 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 5 TLE * 7 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:41:29: warning: ‘tmp’ may be used uninitialized [-Wmaybe-uninitialized] 41 | cout << fact[tmp] << endl; | ^ main.cpp:32:17: note: ‘tmp’ was declared here 32 | int tmp; | ^~~
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #include <math.h> bool is_prime(ll num){ if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; // 偶数はあらかじめ除く double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % 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 << fact[tmp] << endl; } else{ cout << -1 << endl; } } }