結果

問題 No.1237 EXP Multiple!
ユーザー hgoto
提出日時 2020-10-28 15:20:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 724 bytes
コンパイル時間 1,739 ms
コンパイル使用メモリ 195,048 KB
最終ジャッジ日時 2025-01-15 16:08:29
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

inline long long pow(long long a, long long r) {
  long long ret = 1;
  while (r--) ret *= a;
  return ret;
}

inline long long fact(long long a) {
  long long ret = a;
  while (--a) ret *= a;
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << -1 << '\n';
      return 0;
    }
  }
  long long ans = 1;
  const int md = (int)1e9 + 7;
  for (int i = 0; i < n; i++) {
    if (a[i] >= 4 || ans > md) {
      cout << md << '\n';
      return 0;
    }
    ans *= pow(a[i], fact(a[i]));
  }
  cout << md % ans << '\n';
  return 0;
}
0