結果

問題 No.774 tatyamと素数大富豪
ユーザー Shuz*Shuz*
提出日時 2018-06-23 14:24:35
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,400 bytes
コンパイル時間 1,320 ms
コンパイル使用メモリ 146,676 KB
実行使用メモリ 120,692 KB
最終ジャッジ日時 2023-09-13 08:23:07
合計ジャッジ時間 7,045 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 2 ms
4,380 KB
testcase_02 RE -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

bool arr[120000000]={};

void Eratosthenes(int N){
	for(int i = 0; i < N; i++){
		arr[i] = 1;
	}
	for(int i = 2; i < sqrt(N); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) < N; j++){
				arr[i *(j + 2)] = 0;
			}
		}
	}
}

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

    long sqrtNum = sqrtf(num);
    for (long i = 3; i <= sqrtNum; i += 2){
        if(arr[i])
            if (num % i == 0){
            return false;}}
    return true;}

int main(){
    int n,i,p=1,j,k,l;
    ll ans;
    cin>>n;
    int a[n];
    ll t[2*n];
    t[1]=1;
    for(i=2;i-2*n;++i)t[i]=t[i-1]*10;
    Eratosthenes(t[n]*13);
    for(i=0;i-n;++i){cin>>a[i];p*=2;}
    p/=2;
    ll s[256]={},y[256]={};
    int aa=0,bb=0;
    ll max=-1;
    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;}
         ll k=0;
         for(j=0;j-aa;++j)if(s[j]==ans){k=1;break;}
         if(!k)for(j=0;j-bb;++j)if(y[j]==ans){k=1;break;}
         if(!k){
             if(IsPrime(ans)){
             s[aa++]=ans;
             max=max>ans?max:ans;}
             else y[bb++]=ans;
         }}
    cout<<max<<"\n";
}
0