結果
問題 |
No.774 tatyamと素数大富豪
|
ユーザー |
![]() |
提出日時 | 2018-12-22 00:53:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 996 bytes |
コンパイル時間 | 1,879 ms |
コンパイル使用メモリ | 176,728 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-25 09:49:39 |
合計ジャッジ時間 | 5,483 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 WA * 1 |
other | AC * 6 WA * 8 |
ソースコード
#include <bits/stdc++.h> #include <assert.h> using namespace std; long long pow(long long x, long long p, long long mod) { long long ret = 1; while (p > 0) { if (p & 1) ret = ret * x % mod; x = x * x % mod; p >>= 1; } return ret; } bool fermatTest(long long p, int k = 100) { if (p < 2) return false; srand((unsigned)time(NULL)); for (int i = 0; i < k; i++) { long long a = rand() % (p - 1) + 1; if (pow(a, p - 1, p) != 1) // this condition is better than pow(a, p, p) != a return false; } return true; } int main() { int n; cin >> n; vector<string> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); long long ans = 0; do { string tmp; for (int i = 0; i < n; i++) tmp += a[i]; long long check = stoll(tmp); if (fermatTest(check)) ans = max(ans, check); } while (next_permutation(a.begin(), a.end())); cout << (ans == 0 ? -1 : ans) << endl; return 0; }