結果

問題 No.192 合成数
ユーザー fal_rndfal_rnd
提出日時 2017-04-03 19:05:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 911 bytes
コンパイル時間 1,890 ms
コンパイル使用メモリ 73,780 KB
実行使用メモリ 57,756 KB
最終ジャッジ日時 2023-09-09 09:04:51
合計ジャッジ時間 6,611 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,780 KB
testcase_01 AC 117 ms
56,204 KB
testcase_02 AC 119 ms
56,200 KB
testcase_03 AC 116 ms
55,884 KB
testcase_04 AC 117 ms
56,092 KB
testcase_05 AC 116 ms
55,560 KB
testcase_06 AC 118 ms
56,128 KB
testcase_07 AC 120 ms
57,756 KB
testcase_08 AC 117 ms
55,836 KB
testcase_09 AC 120 ms
54,320 KB
testcase_10 AC 118 ms
55,940 KB
testcase_11 AC 117 ms
55,728 KB
testcase_12 AC 116 ms
55,996 KB
testcase_13 AC 120 ms
56,052 KB
testcase_14 AC 121 ms
56,616 KB
testcase_15 AC 119 ms
55,908 KB
testcase_16 AC 120 ms
56,244 KB
testcase_17 AC 121 ms
55,564 KB
testcase_18 AC 121 ms
56,444 KB
testcase_19 AC 120 ms
55,832 KB
testcase_20 AC 118 ms
55,912 KB
testcase_21 AC 118 ms
56,092 KB
testcase_22 AC 125 ms
56,184 KB
testcase_23 AC 118 ms
56,420 KB
testcase_24 AC 118 ms
56,288 KB
testcase_25 AC 118 ms
56,140 KB
testcase_26 AC 116 ms
55,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.BitSet;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main{

	static final Scanner s=new Scanner(System.in);

	public static void main(String args[]){
		int n=Math.max(s.nextInt()-101,3),res;
		PrimeIterator pri = new PrimeIterator(n+100);
		while((res=pri.next())<n);
		System.out.println(res+1);
	}
}
class PrimeIterator{

	private BitSet	bitSet;
	private int		nextV;
	private int		limit;

	public PrimeIterator(int limit){
		this.limit=limit;
		bitSet=new BitSet(limit+1);
		reset();
	}

	public boolean hasNext(){
		return nextV>=0;
	}

	public int next(){
		if(!hasNext())
			throw new NoSuchElementException();
		int r=nextV;
		for(int i=0; i<bitSet.size(); i+=nextV)
			bitSet.set(i);
		nextV=bitSet.nextClearBit(0);

		if(nextV>limit) nextV=-1;
		return r;
	}

	public void reset(){
		nextV=2;
		bitSet.clear();
		bitSet.set(0);
		bitSet.set(1);
	}
}
0