結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー pekempeypekempey
提出日時 2016-05-14 01:27:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 232 ms / 1,000 ms
コード長 1,131 bytes
コンパイル時間 1,178 ms
コンパイル使用メモリ 151,648 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-29 00:56:49
合計ジャッジ時間 5,127 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 7 ms
4,384 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 232 ms
4,380 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 211 ms
4,376 KB
testcase_23 AC 10 ms
4,376 KB
testcase_24 AC 95 ms
4,376 KB
testcase_25 AC 96 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 55 ms
4,380 KB
testcase_29 AC 97 ms
4,380 KB
testcase_30 AC 99 ms
4,376 KB
testcase_31 AC 97 ms
4,376 KB
testcase_32 AC 97 ms
4,380 KB
testcase_33 AC 101 ms
4,380 KB
testcase_34 AC 109 ms
4,376 KB
testcase_35 AC 103 ms
4,376 KB
testcase_36 AC 149 ms
4,380 KB
testcase_37 AC 99 ms
4,380 KB
testcase_38 AC 109 ms
4,376 KB
testcase_39 AC 96 ms
4,380 KB
testcase_40 AC 101 ms
4,376 KB
testcase_41 AC 105 ms
4,380 KB
testcase_42 AC 111 ms
4,376 KB
testcase_43 AC 95 ms
4,380 KB
testcase_44 AC 6 ms
4,376 KB
testcase_45 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

	const int N = 3e5 + 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 <= 10000) {
		pair<long long, long long> ans;
		for (long long i = L; i <= H; i++) {
			long long p = 1;
			for (long long j = 2; j * j <= i; j++) {
				if (i % j == 0) {
					p = j;
					break;
				}
			}
			if (p != 1) ans = max(ans, make_pair(p, i));
		}
		cout << ans.second << endl;
		return 0;
	}

	vector<vector<long long>> dp(40);
	dp[0].push_back(1);
	for (int i = primes.size() - 1; i >= 0; i--) {
		for (int j = 0; j < 39; j++) {
			for (long long x : dp[j]) {
				if (x * primes[i] <= H) {
					dp[j + 1].push_back(x * primes[i]);
				}
			}
		}
		long long ans = 0;
		for (int j = 2; j < 39; j++) {
			for (long long x : dp[j]) {
				if (L <= x && x <= H) ans = max(ans, x);
			}
		}
		if (ans != 0) {
			cout << ans << endl;
			return 0;
		}
	}
	cout << "fail" << endl;
}
0