結果
問題 |
No.774 tatyamと素数大富豪
|
ユーザー |
![]() |
提出日時 | 2020-07-18 13:51:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 109 ms / 2,000 ms |
コード長 | 897 bytes |
コンパイル時間 | 2,532 ms |
コンパイル使用メモリ | 209,432 KB |
最終ジャッジ日時 | 2025-01-12 00:16:29 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 14 |
ソースコード
#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"; }