結果
問題 |
No.1237 EXP Multiple!
|
ユーザー |
|
提出日時 | 2020-09-26 01:12:19 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 88 ms / 2,000 ms |
コード長 | 1,378 bytes |
コンパイル時間 | 1,540 ms |
コンパイル使用メモリ | 140,764 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 09:14:18 |
合計ジャッジ時間 | 3,551 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 19 |
ソースコード
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; ll limit = 1000000007; ll modpow(ll x, ll n) { ll ans = 1; while(n > 0) { if(n % 2 == 1) { ans *= x; // ans %= MOD; if(ans > limit) { return -1; } } x *= x; // x %= MOD; if(x > limit && n > 1) { return -1; } n >>= 1; } return ans; } int main() { int n; cin >> n; ll num = 1; vector<int> input(n); for(int i = 0; i < n; i++) { cin >> input[i]; } if(*min_element(input.begin(), input.end()) == 0) { cout << -1 << '\n'; return 0; } if(*max_element(input.begin(), input.end()) > 3) { cout << limit << '\n'; return 0; } for(int i = 0; i < n; i++) { ll tmp, a, cnt = 1; a = input[i]; if(a < 2) { continue; } tmp = a; while(tmp--) { cnt *= (tmp + 1); } if(modpow(a, cnt) > limit) { cout << limit << '\n'; return 0; } else if(modpow(a, cnt) == -1) { cout << limit << '\n'; return 0; } num *= modpow(a, cnt); if(num > limit) { cout << limit << '\n'; return 0; } } cout << limit % num << '\n'; return 0; }