結果
問題 | No.371 ぼく悪いプライムじゃないよ |
ユーザー | Grenache |
提出日時 | 2016-06-21 19:34:15 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 89 ms / 1,000 ms |
コード長 | 2,980 bytes |
コンパイル時間 | 4,109 ms |
コンパイル使用メモリ | 79,732 KB |
実行使用メモリ | 52,072 KB |
最終ジャッジ日時 | 2024-06-09 19:28:27 |
合計ジャッジ時間 | 8,519 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
50,540 KB |
testcase_01 | AC | 57 ms
50,456 KB |
testcase_02 | AC | 54 ms
50,012 KB |
testcase_03 | AC | 55 ms
50,332 KB |
testcase_04 | AC | 56 ms
50,552 KB |
testcase_05 | AC | 57 ms
50,544 KB |
testcase_06 | AC | 56 ms
50,532 KB |
testcase_07 | AC | 57 ms
52,072 KB |
testcase_08 | AC | 56 ms
50,416 KB |
testcase_09 | AC | 56 ms
50,416 KB |
testcase_10 | AC | 55 ms
50,332 KB |
testcase_11 | AC | 58 ms
50,484 KB |
testcase_12 | AC | 57 ms
50,140 KB |
testcase_13 | AC | 57 ms
50,316 KB |
testcase_14 | AC | 57 ms
50,360 KB |
testcase_15 | AC | 56 ms
50,372 KB |
testcase_16 | AC | 57 ms
50,524 KB |
testcase_17 | AC | 56 ms
50,576 KB |
testcase_18 | AC | 57 ms
50,568 KB |
testcase_19 | AC | 57 ms
50,532 KB |
testcase_20 | AC | 56 ms
50,392 KB |
testcase_21 | AC | 57 ms
50,148 KB |
testcase_22 | AC | 59 ms
50,400 KB |
testcase_23 | AC | 57 ms
50,360 KB |
testcase_24 | AC | 79 ms
51,148 KB |
testcase_25 | AC | 77 ms
51,260 KB |
testcase_26 | AC | 89 ms
51,240 KB |
testcase_27 | AC | 76 ms
51,252 KB |
testcase_28 | AC | 84 ms
51,204 KB |
testcase_29 | AC | 86 ms
51,116 KB |
testcase_30 | AC | 87 ms
51,012 KB |
testcase_31 | AC | 86 ms
51,192 KB |
testcase_32 | AC | 73 ms
51,204 KB |
testcase_33 | AC | 77 ms
51,212 KB |
testcase_34 | AC | 83 ms
51,296 KB |
testcase_35 | AC | 85 ms
51,124 KB |
testcase_36 | AC | 77 ms
50,964 KB |
testcase_37 | AC | 76 ms
51,252 KB |
testcase_38 | AC | 85 ms
51,368 KB |
testcase_39 | AC | 84 ms
51,224 KB |
testcase_40 | AC | 78 ms
51,032 KB |
testcase_41 | AC | 74 ms
50,896 KB |
testcase_42 | AC | 84 ms
50,916 KB |
testcase_43 | AC | 82 ms
51,200 KB |
testcase_44 | AC | 82 ms
50,920 KB |
testcase_45 | AC | 57 ms
50,584 KB |
ソースコード
import java.io.*; import java.util.*; public class Main_yukicoder371 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); long l = sc.nextLong(); long h = sc.nextLong(); Prime prime = new Prime((int)Math.sqrt(h)); List<Integer> primes = prime.getPrimeList(); for (int i = primes.size() - 1; i >= 0; i--) { int p = primes.get(i); for (long j = h / p; j * p >= l; j--) { if (j < p) { break; } boolean flag = true; for (long e : primes) { if (e >= p) { break; } if (e * e > j) { break; } if (j % e == 0) { flag = false; break; } } if (flag) { pr.println(j * p); sc.close(); pr.close(); return; } } } pr.close(); sc.close(); } @SuppressWarnings("unused") private static class Prime { private int n; private List<Integer> primes; private BitSet p; Prime(int n) { this.n = n; p = new BitSet(n / 2); int m = (int)Math.sqrt(n); for (int i = 1; i <= m; i++) { if (p.get(i - 1)) { continue; } for (int j = 2 * i * (i + 1); 2 * j + 1 <= n; j += 2 * i + 1) { p.set(j - 1); } } } boolean isPrime(int n) { if (n == 2) { return true; } if (n == 1 || (n & 0x1) == 0) { return false; } return !p.get(n / 2 - 1); } List<Integer> getPrimeList() { if (primes != null) { return primes; } primes = new ArrayList<>(); primes.add(2); for (int i = 1; 2 * i + 1 <= n; i++) { if (!p.get(i - 1)) { primes.add(2 * i + 1); } } return primes; } private static boolean isPrime(long n) { if (n == 2) { return true; } if (n == 1 || (n & 0x1) == 0) { return false; } for (long i = 3; i * i <= n; i += 2) { if (n % i == 0) { return false; } } return true; } } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }