結果

問題 No.371 ぼく悪いプライムじゃないよ
コンテスト
ユーザー mizzsig
提出日時 2016-12-01 11:00:41
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 783 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 617 ms
コンパイル使用メモリ 93,500 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2026-05-21 21:41:59
合計ジャッジ時間 4,029 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 2
other AC * 12 WA * 6 TLE * 1 -- * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/iostream:43,
                 from main.cpp:3:
In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]',
    inlined from 'int main()' at main.cpp:46:10:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:212:25: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
  212 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:28:19: note: 'ans' was declared here
   28 |         long long ans;
      |                   ^~~

ソースコード

diff #
raw source code

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

using namespace std;

vector<int> Eratosthenes(int n){
	bool dp[n];
	for(int i = 0; i < n; i++) dp[i] = false;
	dp[0] = dp[1] = true;
	vector<int> prime;
	for(int i = 2; i < n; i++){
		if(dp[i]) continue;
		prime.push_back(i);
		for(int j = i * i; j < n; j += i){
			dp[j] = true;
		}
	}
	return prime;
}

int main(){
	long long l, h;
	cin >> l >> h;
	vector<int> prime = Eratosthenes(10000);

	long long ans;
	long long so = -1;
	if(l % 2 == 0){
		l++;
	}
	for(long long i = l; i <= h; i += 2){
		for(long long j = 0; j < prime.size(); j++){
			if(i % prime[j] == 0){
				if(i == prime[j]) break;
				if(so < j){
					ans = i;
					so = j;
				}
				break;
			}
		}
	}

	cout << ans << endl;

	return 0;
}
0