結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-05-24 18:42:53
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,861 bytes
コンパイル時間 1,304 ms
コンパイル使用メモリ 160,740 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-16 12:21:00
合計ジャッジ時間 5,635 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 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 AC 2 ms
5,376 KB
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 9 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 AC 2 ms
5,376 KB
testcase_20 TLE -
testcase_21 AC 4 ms
5,376 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    ll L, H;
    void input() {
        cin >> L >> H;
    }

    const ll X = ll(1e10 + 2);
    const ll sqX = ll(1e5 + 10);

    bool isPrime[sqX];
    vector<ll> primes;
    void init() {
        memset(isPrime, 1, sizeof(isPrime));
        isPrime[0] = isPrime[1] = false;
        for (int i = 2; i < sqX; i++) {
            if (isPrime[i]) {
                primes.push_back(i);
                for (int j = i + i; j < sqX; j += i) {
                    isPrime[j] = false;
                }
            }
        }
    }

    ll minFactor(ll x) {
        for (ll i = 2; i * i <= x; i++) {
            if (x % i == 0) return i;
        }
        return -1;
        //return x;
    }

    bool C(ll x, ll y) {
        ll mx = minFactor(x),
           my = minFactor(y);
        if (mx == my) return mx > my;
        return mx > my;
    }

    ll MAX(ll x, ll y) {
        if (C(x, y)) return x;
        else return y;
    }

    ll dfs(ll lb, ll ub) {
        if (ub - lb == 1) {
            return MAX(lb, ub);
        } else if (ub - lb == 0) {
            return lb;
        }
        ll mid = (lb + ub) / 2;
        ll x = dfs(lb, mid);
        ll y = dfs(mid + 1, ub);
        return MAX(x, y);
    }

    void solve() {
        cout << dfs(L, H) << endl;
    }
}

int main() {
    init();
    input(); solve();
    return 0;
}
0