結果

問題 No.774 tatyamと素数大富豪
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-10-07 16:32:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,306 bytes
コンパイル時間 1,683 ms
コンパイル使用メモリ 170,876 KB
実行使用メモリ 7,568 KB
最終ジャッジ日時 2023-09-27 09:18:26
合計ジャッジ時間 9,240 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘bool MillerRabin(long long int, int)’ 内:
main.cpp:33:17: 警告: ‘j’ may be used uninitialized [-Wmaybe-uninitialized]
   33 |                 if(j==s) return false;
      |                 ^~
main.cpp:19:19: 備考: ‘j’ はここで定義されています
   19 |         int s=0,i,j;
      |                   ^

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.10.07 16:32:25
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

long long modpow(__int128_t a, long long n, long long mo) {
	__int128_t r=1;
	a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}
bool MillerRabin(long long v,int loop=10) {
	long long d=v-1;
	int s=0,i,j;
	if(v<=1) return false;
	if(v==2) return true;
	if(v%2==0) return false;
	while(d%2==0) d/=2,s++;
	
	for (int i = 0;i < loop; i++) {
		ll a=abs(1LL*rand()*rand()+rand())%(v-2)+1;
		ll r=modpow(a,d,v);
		if(r==1 || r==v-1) continue;
		for (int j = 0; j < s; j++) {
			r=modpow(r,2,v);
			if(r==v-1) break;
		}
		if(j==s) return false;
	}
	return true;
}
int main() {
    int n;
    cin >> n;
    vector< int > a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    ll ans = -1;
    do {
        ll num = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] >= 10) {
                num *= 100;
                num += a[i];
            } else {
                num *= 10;
                num += a[i];
            }
        }
        
        if (MillerRabin(num)) ans = max(ans, num);
    } while (next_permutation(a.begin(), a.end()));
    cout << ans << endl;
    return 0;
}
0