結果

問題 No.774 tatyamと素数大富豪
ユーザー ninoinuininoinui
提出日時 2020-07-18 13:51:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 897 bytes
コンパイル時間 2,529 ms
コンパイル使用メモリ 214,380 KB
実行使用メモリ 8,548 KB
最終ジャッジ日時 2023-08-20 17:18:44
合計ジャッジ時間 3,898 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
8,548 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 25 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 40 ms
5,208 KB
testcase_13 AC 44 ms
5,188 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

bool isp(long n) {
  if (n < 2) return false;
  long s = __builtin_ctzl(n - 1), d = n >> s;
  for (auto b : {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) {
    long p = 1, i = s, j = d, k = b;
    while (j > 0) {
      if (j & 1) p = (__int128) p * k % n;
      k = (__int128) k * k % n;
      j >>= 1;
    }
    while (p != 1 && p != n - 1 && b % n && i--) p = (__int128) p * p % n;
    if (p != n - 1 && i != s) return false;
  }
  return true;
}

int main() {
  int N;
  cin >> N;
  vector<string> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<long> V;
  sort(A.begin(), A.end());
  do {
    string tmp;
    for (auto a : A) tmp += a;
    V.push_back(stol(tmp));
  } while (next_permutation(A.begin(), A.end()));
  sort(V.rbegin(), V.rend());
  for (auto v : V) if (isp(v)) return cout << v << "\n", 0;
  cout << -1 << "\n";
}
0