結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー pekempeypekempey
提出日時 2016-05-14 00:25:38
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 881 bytes
コンパイル時間 1,232 ms
コンパイル使用メモリ 165,220 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 17:54:41
合計ジャッジ時間 3,575 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 27 ms
6,944 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 3 ms
6,944 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 15 ms
6,940 KB
testcase_22 WA -
testcase_23 AC 12 ms
6,940 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 3 ms
6,940 KB
testcase_28 AC 11 ms
6,948 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 3 ms
6,940 KB
testcase_32 AC 3 ms
6,944 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 3 ms
6,944 KB
testcase_35 AC 3 ms
6,944 KB
testcase_36 AC 3 ms
6,944 KB
testcase_37 WA -
testcase_38 AC 3 ms
6,944 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 TLE -
testcase_44 AC 3 ms
6,940 KB
testcase_45 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
	long long L, H;
	cin >> L >> H;

	const int N = 2e5 + 100;
	vector<long long> primes;
	vector<char> is_prime(N, true);

	for (int i = 2; i < N; i++) {
		if (is_prime[i]) {
			primes.push_back(i);
			for (int j = i * 2; j < N; j += i) {
				is_prime[j] = false;
			}
		}
	}

	if (H - L <= 200200) {
		pair<long long, long long> ans;
		for (long long i = L; i <= H; i++) {
			long long p = 1;
			for (int j = 0; j < primes.size(); j++) {
				if (i % primes[j] == 0) {
					if (i != primes[j]) p = primes[j];
					break;
				}
			}
			if (p != 1) ans = max(ans, make_pair(p, i));
		}
		cout << ans.second << endl;
		return 0;
	}

	for (int i = primes.size() - 1; i >= 0; i--) {
		long long cand = primes[i] * primes[i];
		if (L <= cand && cand <= H) {
			cout << cand << endl;
			return 0;
		}
	}
	cout << "fail" << endl;
}
0