結果

問題 No.774 tatyamと素数大富豪
ユーザー kriiikriii
提出日時 2018-12-25 16:24:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,001 ms / 2,000 ms
コード長 1,187 bytes
コンパイル時間 532 ms
コンパイル使用メモリ 59,312 KB
実行使用メモリ 17,280 KB
最終ジャッジ日時 2024-04-08 22:32:38
合計ジャッジ時間 4,056 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,001 ms
17,280 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 4 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 17 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 8 ms
6,676 KB
testcase_12 AC 471 ms
10,752 KB
testcase_13 AC 267 ms
11,136 KB
testcase_14 AC 5 ms
6,676 KB
testcase_15 AC 10 ms
6,676 KB
testcase_16 AC 6 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 6 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
using ll = long long;

ll p[]={2,3,5,7,11,13,17,19,23};ll sqa(ll a,ll b,ll c){ll ret = 1;while(b){if(b&1)ret=(__int128)ret*a%c;a=(__int128)a*a%c;b>>=1;}return ret;}bool ML(ll x){if(x==2)return true;if(x<2||!(x&1))return false;ll y = x-1;int s = 0;while((y&1)==0)y>>=1,s++;for(ll c :p){if(c>=x)return true;ll d = sqa(c,y,x);if(d==1)continue;for(int j=0;j<s;j++){ll t = (__int128)d*d%x;if(t==1 && d!=1 && d!=x-1)return false;d = t;}if(d!=1)return false;}return true;}ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}ll div(ll x){ll a=rand()%(x-1)+1,b=a,i=1,k=2;ll c=1;do{i++;ll d = gcd(b-a+x,x);if(d!=1 && d!=x)return d;if(i==k)b=a,k<<=1;a=((__int128)a*a+x-c)%x;}while(a!=b);return x;}

int main()
{
	int N; scanf ("%d",&N);
	int A[10]; for (int i=0;i<N;i++) scanf ("%d",&A[i]);

	long long ans = -1;
	set<long long> chk;
	do{
		long long a = 0;
		for (int i=0;i<N;i++){
			if (A[i] < 10) a = a * 10 + A[i];
			else a = a * 100 + A[i];
		}
		if (chk.count(a)) continue;
		else{
			chk.insert(a);
			if (ML(a)) ans = max(ans,a);
		}
	}while(next_permutation(A,A+N));

	printf ("%lld\n",ans);
	return 0;
}
0