結果

問題 No.774 tatyamと素数大富豪
ユーザー Shuz*
提出日時 2018-06-22 08:02:56
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 914 bytes
コンパイル時間 1,307 ms
コンパイル使用メモリ 160,956 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-06-30 17:53:12
合計ジャッジ時間 5,183 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 TLE * 1 -- * 3
other WA * 1 -- * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

bool IsPrime(long num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    float sqrtNum = sqrtf(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0){
            return false;}}
    return true;}

int main(){
    long n,i,p=1,ans,j,k,l;
    cin>>n;
    int a[n];
    int t[3*n];
    t[1]=1;
    for(i=2;i-3*n;++i)t[i]=t[i-1]*10;
    for(i=0;i-n;++i)cin>>a[i],p*=2;
    long s[512]={},m=0;
    for(i=0;i-p;++i){
         k=i;
         ans=a[0];
         l=a[0]>9?2:1;
         for(j=1;j-n;++j){
             l+=a[j]>9?2:1;
             if(k%2)ans+=a[j]*t[l];
             else{ans*=a[j]>9?100:10;ans+=a[j];}
             k/=2;}
         if(IsPrime(ans))s[m++]=ans;}
    int max=0;
    for(i=0;i-512;++i)max=max>s[i]?max:s[i];
    if(max)cout<<max<<"\n";
    else cout<<"No"<<"\n";
}

0