結果
| 問題 |
No.774 tatyamと素数大富豪
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-22 16:07:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,547 bytes |
| コンパイル時間 | 1,067 ms |
| コンパイル使用メモリ | 83,084 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-11 19:15:49 |
| 合計ジャッジ時間 | 1,938 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 WA * 1 |
| other | AC * 12 WA * 2 |
コンパイルメッセージ
main.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
54 | main()
| ^~~~
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long to_i(string s)
{
long ret=0;
for(char c:s)ret=ret*10+c-'0';
return ret;
}
long mul(long a,long b,long c)
{
const long B=1e9;
long aa=a/B,ab=a%B;
long ba=b/B,bb=b%B;
long up=aa*ba%c;
for(int i=0;i<18;i++)up=up*10%c;
long mid=(aa*bb+ab*ba)%c;
for(int i=0;i<9;i++)mid=mid*10%c;
long low=ab*bb%c;
return(up+mid+low)%c;
}
long power(long a,long b,long c)
{
if(b==0)return 1L;
else if(b%2==0)return power(mul(a,a,c),b/2,c);
else return mul(a,power(a,b-1,c),c);
}
bool isp(long N)
{
if(N%7==0||N%11==0||N%13==0||N%17==0||N%19==0)return false;
long s=0,d=N-1;
while(d%2==0)
{
s++;
d/=2;
}
for(long a=2;a<=84&&a<N;a++)
{
long ad=power(a,d,N);
bool flag=ad!=1;
if(flag)
{
for(int r=0;r<s;r++)
{
flag=flag&&ad!=N-1;
ad=mul(ad,ad,N);
}
}
if(flag)return false;
}
return true;
}
main()
{
int N;cin>>N;
int cs=0;
vector<string>A(N);
for(int i=0;i<N;i++)
{
cin>>A[i];
for(char c:A[i])cs+=c-'0';
}
sort(A.begin(),A.end());
if(N==1)
{
string s=A[0];
if(s=="2"||s=="3"||s=="5"||s=="7"||s=="11"||s=="13")
{
cout<<s<<endl;
}
else
{
cout<<-1<<endl;
}
return 0;
}
if(cs%3==0)
{
cout<<-1<<endl;
return 0;
}
long ans=-1;
prev_permutation(A.begin(),A.end());
do{
if(to_i(A.back())%2==0||to_i(A.back())%5==0)continue;
string now="";
for(string a:A)now+=a;
long X=to_i(now);
if(isp(X))
{
ans=X;
break;
}
}while(prev_permutation(A.begin(),A.end()));
cout<<ans<<endl;
}