結果

問題 No.1237 EXP Multiple!
ユーザー polyesterpolyester
提出日時 2020-09-26 01:07:20
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,510 bytes
コンパイル時間 2,382 ms
コンパイル使用メモリ 105,080 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 17:56:29
合計ジャッジ時間 4,761 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 56 ms
4,380 KB
testcase_02 AC 77 ms
4,380 KB
testcase_03 AC 78 ms
4,380 KB
testcase_04 AC 86 ms
4,376 KB
testcase_05 AC 32 ms
4,376 KB
testcase_06 AC 32 ms
4,376 KB
testcase_07 AC 33 ms
4,376 KB
testcase_08 AC 32 ms
4,380 KB
testcase_09 AC 31 ms
4,380 KB
testcase_10 AC 32 ms
4,384 KB
testcase_11 AC 32 ms
4,380 KB
testcase_12 AC 32 ms
4,380 KB
testcase_13 WA -
testcase_14 AC 32 ms
4,380 KB
testcase_15 AC 31 ms
4,376 KB
testcase_16 AC 32 ms
4,380 KB
testcase_17 AC 32 ms
4,376 KB
testcase_18 AC 32 ms
4,380 KB
testcase_19 AC 31 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }
    num *= modpow(a, cnt);
    if(num > limit) {
      cout << limit << '\n';
      return 0;
    } else if(num < 0) {
      cout << limit << '\n';
      return 0;
    } else if(limit % num == 0) {
      cout << -1 << '\n';
      return 0;
    }
  }
  if(limit % num == 0) {
    // cout << -1 << '\n';
  } else {
    cout << limit % num << '\n';
  }
  return 0;
}
0