結果

問題 No.774 tatyamと素数大富豪
ユーザー goodbatongoodbaton
提出日時 2018-12-25 13:55:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,618 bytes
コンパイル時間 1,188 ms
コンパイル使用メモリ 103,600 KB
実行使用メモリ 12,048 KB
最終ジャッジ日時 2023-07-24 18:11:08
合計ジャッジ時間 7,695 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdint>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifdef LOCAL
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define debug(x) ;
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

typedef __int128_t Int;

Int power(Int k, Int n, ll M){
  if(n==0) return 1;
  if(n==1) return k % M;

  Int res = power(k, n/2, M);

  res = res * res % M;

  if(n % 2)
    res = k % M * res % M;

  return res;
}

bool isPrime(Int x) {
  srand(time(NULL));
  if(x == 2) return true;
  if(x <= 1 || x % 2 == 0) return false;
  Int d = x-1;
  while(d%2 == 0) d >>= 1;
  for(int i=0;i<30;i++){
    Int a = rand() % (x-2) + 1;
    Int t = d;
    Int y = power(a, t, x);
    while(t != x-1 && y != 1 && y != x-1){
      y = (y * y) % x;
      t <<= 1;
    }
    if(y != x-1 && t%2 == 0) return false;
  }
  return true;
}

int main(){
  string s[14];
  int n;

  scanf("%d", &n);

  for(int i=0;i<n;i++) cin >> s[i];

  sort(s, s+n);

  ll ans = -1;

  do{
    string t;

    for(int i=0;i<n;i++){
      t += s[i];
    }
    ll a = stoll(t);
    if(isPrime(a)) ans = max(ans, a);
  }while(next_permutation(s, s+n));

  cout << ans << endl;

  return 0;
}
0