結果

問題 No.774 tatyamと素数大富豪
ユーザー daddydaddy
提出日時 2023-03-01 22:33:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,841 bytes
コンパイル時間 1,936 ms
コンパイル使用メモリ 174,488 KB
実行使用メモリ 11,876 KB
最終ジャッジ日時 2023-10-15 02:07:17
合計ジャッジ時間 8,461 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 #

#pragma GCC optimization ("O3")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;
using dvec = vector<double>;
using dmat = vector<dvec>;

#define INF (1LL<<61)
#define MOD 1000000007LL 
//#define MOD 998244353LL

#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORE(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) {ASC((x)); REV((x));}
#define BIT(s,i) (((s)>>(i))&1)
#define pb push_back
#define fi first
#define se second

template<class T> inline int chmin(T& a, T b) {if(a>b) {a=b; return 1;} return 0;}
template<class T> inline int chmax(T& a, T b) {if(a<b) {a=b; return 1;} return 0;}

class mint {
public:
    ll x;
    mint(ll x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const {return mint(-x);}
    mint& operator+=(const mint& a) {if((x+=a.x)>=MOD) x-=MOD; return *this;}
    mint& operator-=(const mint& a) {if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
    mint& operator*=(const mint& a) {(x*=a.x)%=MOD; return *this;}
    mint operator+(const mint& a) const {mint b(*this); return b+=a;}
    mint operator-(const mint& a) const {mint b(*this); return b-=a;}
    mint operator*(const mint& a) const {mint b(*this); return b*=a;}
    mint pow(ll t) const {if(!t) return 1; mint a=pow(t>>1); return (t&1?*this*a:a)*a;}
    mint inv() const {return pow(MOD-2);}
    mint& operator/=(const mint& a) {return *this*=a.inv();}
    mint operator/(const mint& a) const {mint b(*this); return b/=a;}
};
istream &operator>>(istream& is, mint& a) {ll t; is>>t; a=t; return is;}
ostream &operator<<(ostream& os, const mint& a) {return os<<a.x;}
using mvec = vector<mint>;
using mmat = vector<mvec>;

ll modpow(ll a, ll n, ll m)
{
    if(n == 0) return 1;
    ll t = modpow(a, n/2, m);
    t = (ll)((__int128)t*t%m);
    if(n%2) t = (ll)((__int128)t*a%m);
    return t;
}

bool miller_rabin(ll n)
{
    if(n <= 1) return false;
    if(n == 2) return true;
    if(n > 2 && n%2 == 0) return false;
    ll s = 0, t = n-1;
    while(t%2 == 0) ++s, t /= 2;
    ll a = rand()%(n-1)+1;
    if(modpow(a, t, n) == 1) return true;
    REP(i,0,s) {
        if(modpow(a, modpow(2, i, INF)*t, n) == n-1) return true;
    }
    return false;
}

int main()
{
    ll N;
    cin >> N;
    vec A(N);
    REP(i,0,N) cin >> A[i];
    ASC(A);

    ll ans = -1;
    srand(time(NULL));
    do {
        string s;
        REP(i,0,N) s += to_string(A[i]);
        ll p = stoll(s);
        bool f = true;
        REP(i,0,50) f &= miller_rabin(p);
        if(f) chmax(ans, p);
    } while(next_permutation(ALL(A)));
    PR(ans);

    return 0;
}

/*



*/
0