結果
| 問題 |
No.774 tatyamと素数大富豪
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-22 15:55:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,205 bytes |
| コンパイル時間 | 1,363 ms |
| コンパイル使用メモリ | 81,492 KB |
| 実行使用メモリ | 13,952 KB |
| 最終ジャッジ日時 | 2024-10-11 18:53:47 |
| 合計ジャッジ時間 | 7,982 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 5 |
| other | TLE * 1 -- * 13 |
コンパイルメッセージ
main.cpp:57:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
57 | 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)
{
long ret=0;
while(b)
{
if(b&1)
{
ret+=a;
ret%=c;
}
a+=a;
a%=c;
b>>=1;
}
return ret;
}
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)
{
long s=0,d=N-1;
while(d%2==0)
{
s++;
d/=2;
}
for(long a=2;a<=100&&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;
vector<string>A(N);
for(int i=0;i<N;i++)cin>>A[i];
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;
}
long ans=-1;
do{
if(to_i(A.back())%2==0)continue;
string now="";
for(string a:A)now+=a;
long X=to_i(now);
if(isp(X)&&ans<X)ans=X;
}while(next_permutation(A.begin(),A.end()));
cout<<ans<<endl;
}