結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー masamasa
提出日時 2016-05-13 23:53:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,211 bytes
コンパイル時間 692 ms
コンパイル使用メモリ 69,252 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 17:25:56
合計ジャッジ時間 2,072 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>

using namespace std;

const int H_MAX_RT = 1e5;

vector<long long> primes;

void make_primes() {
	vector<bool> is_prime(H_MAX_RT + 100, true);
	is_prime[0] = is_prime[1] = false;

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

	for (int i = 0; i < n; i++) {
		if (is_prime[i]) {
			primes.emplace_back(i);
		}
	}
}

int main() {
	make_primes();

	long long l, h;
	cin >> l >>  h;
	long long diff = h - l + 1;
	if (diff == 2) {
		cout << (l % 2 == 0 ? l : h) << endl;
		return 0;
	}
	auto it = upper_bound(primes.begin(), primes.end(), diff);
	int idx = it - primes.begin();
	do {
		idx--;
	} while (primes[idx] * primes[idx] > h);


	do {
		for (long long i = h; i >= l; i--) {
			if (i % primes[idx] == 0) {
				long long tmp = i / primes[idx];
				bool is_ok = true;

				for (int i = 0; i < idx; i++) {
					if (tmp % primes[i] == 0) {
						is_ok = false;
					}
				}
				if (is_ok) {
					cout << i << endl;
					return 0;
				}
			}
		}

		idx--;
	} while (idx > 0);

	return 0;
}
0