結果
| 問題 |
No.774 tatyamと素数大富豪
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2018-12-22 10:06:27 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 43 ms / 2,000 ms |
| コード長 | 1,492 bytes |
| コンパイル時間 | 1,410 ms |
| コンパイル使用メモリ | 102,904 KB |
| 実行使用メモリ | 7,396 KB |
| 最終ジャッジ日時 | 2024-10-01 13:23:02 |
| 合計ジャッジ時間 | 2,110 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 14 |
ソースコード
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll powmod(__int128_t a, ll k, ll m){
__int128_t ap=a, ans=1;
while(k){
if(k&1){
ans*=ap;
ans%=m;
}
k>>=1;
ap=ap*ap%m;
}
return ans;
}
random_device rnd;
mt19937_64 mt(rnd());
bool is_prime(ll n){
if(n<=1) return false;
if(n==2) return true;
if(!(n&1)) return false;
ll d=n-1;
int k=0;
while(!(d&1)){
d>>=1;
k++;
}
uniform_int_distribution<ll> rndn(2, n-1);
for(int i=0; i<10; i++){
ll a=rndn(mt);
bool comp=1;
ll ap=powmod(a, d, n);
if(ap==1 || ap==n-1) continue;
for(int r=1; r<k; r++){
ap=powmod(ap, 2, n);
if(ap==n-1){
comp=0;
break;
}
}
if(comp) return false;
}
return true;
}
int main()
{
int n; cin>>n;
ll a[9];
for(int i=0; i<n; i++) cin>>a[i];
vector<ll> v;
while(1){
ll p10=1, p=0;
for(int i=0; i<n; i++){
p+=(p10*a[i]);
if(a[i]>=10) p10*=100;
else p10*=10;
}
v.push_back(p);
if(!next_permutation(a, a+n)) break;
}
sort(v.begin(), v.end(), greater<ll>());
for(int i=0; i<v.size(); i++){
if(is_prime(v[i])){
cout<<v[i]<<endl;
return 0;
}
}
cout<<-1<<endl;
return 0;
}
chocorusk