結果

問題 No.726 Tree Game
ユーザー はまやんはまやんはまやんはまやん
提出日時 2018-08-25 09:14:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,585 bytes
コンパイル時間 1,697 ms
コンパイル使用メモリ 169,876 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-24 21:20:32
合計ジャッジ時間 2,571 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
#ifdef _MSC_VER
#pragma push_macro("long")
#undef long
#ifdef _WIN32
inline unsigned int __builtin_ctz(unsigned int x) { unsigned long r; _BitScanForward(&r, x); return r; }
inline unsigned int __builtin_clz(unsigned int x) { unsigned long r; _BitScanReverse(&r, x); return 31 - r; }
inline unsigned int __builtin_ffs(unsigned int x) { unsigned long r; return _BitScanForward(&r, x) ? r + 1 : 0; }
inline unsigned int __builtin_popcount(unsigned int x) { return __popcnt(x); }
inline unsigned int hidword(unsigned long long x) { return static_cast<unsigned int>(x >> 32); }
inline unsigned int lodword(unsigned long long x) { return static_cast<unsigned int>(x & 0xFFFFFFFF); }
inline unsigned long long __builtin_ctzll(unsigned long long x) { return lodword(x) ? __builtin_ctz(lodword(x)) : __builtin_ctz(hidword(x)) + 32; }
inline unsigned long long __builtin_clzll(unsigned long long x) { return hidword(x) ? __builtin_clz(hidword(x)) : __builtin_clz(lodword(x)) + 32; }
inline unsigned long long __builtin_ffsll(unsigned long long x) { return lodword(x) ? __builtin_ffs(lodword(x)) : hidword(x) ? __builtin_ffs(hidword(x)) + 32 : 0; }
inline unsigned long long __builtin_popcountll(unsigned long long x) { return __builtin_popcount(lodword(x)) + __builtin_popcount(hidword(x)); }
#endif // _WIN32
#pragma pop_macro("long")
#endif // _MSC_VER
typedef long long ll;
typedef __int128 int128_t;
//typedef ll int128_t;
int128_t powmod(int128_t x, int128_t y, int128_t p) { // O(log y)
    assert(0 <= x and x < p);
    assert(0 <= y);
    int128_t z = 1;
    for (int128_t i = 1; i <= y; i <<= 1) {
        if (y & i) z = z * x % p;
        x = x * x % p;
    }
    return z;
}
int K = 10;
int getrand(int l, int r) { // [l, r]
    static uint32_t y = time(NULL);
    y ^= (y << 13); y ^= (y >> 17);
    y ^= (y << 5);
    return y % (r - l + 1) + l;
}
ll getrandll(ll l, ll r) { // [l,r]
    ll a = getrand(0, 999999999);
    ll b = getrand(0, 999999999);

    ll x = a * 1000000000LL + b;
    assert(0 <= x);

    return x % (r - l + 1) + l;
}
bool isprime(ll v, int loop = 50) {
    ll 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++;

    rep(i, 0, loop) {
        ll a = getrandll(1, v - 1);
        ll r = powmod(a, d, v);
        if (r == 1 || r == v - 1) continue;
        int j;
        for (j = 0; j < s; j++) {
            r = powmod(r, 2, v);
            if (r == v - 1) break;
        }
        if (j == s) return false;
    }
    return true;
}
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/




int Y, X;
//---------------------------------------------------------------------------------------------------
#define first "First"
#define second "Second"
string solve() {
    if (isprime(X) and isprime(Y)) return second;
    if (X == 2 or Y == 2) return second;
    int rev = 0;
    if (isprime(X)) rev = 1, X++;
    else if (isprime(Y)) rev = 1, Y++;

    int x = X, y = Y;
    while (!isprime(x)) x++;
    while (!isprime(y)) y++;

    int d = 1LL * (y - Y) * (x - X);
    if (d % 2 == 0) {
        if (rev == 0) return first;
        else return second;
    }
    if (rev == 0) return second;
    else return first;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> Y >> X;
    cout << solve() << endl;
}
0