結果
問題 | No.371 ぼく悪いプライムじゃないよ |
ユーザー | Grenache |
提出日時 | 2016-06-21 19:34:15 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 66 ms / 1,000 ms |
コード長 | 2,980 bytes |
コンパイル時間 | 3,788 ms |
コンパイル使用メモリ | 76,864 KB |
実行使用メモリ | 51,464 KB |
最終ジャッジ日時 | 2023-08-29 01:08:45 |
合計ジャッジ時間 | 7,932 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
49,408 KB |
testcase_01 | AC | 46 ms
49,704 KB |
testcase_02 | AC | 46 ms
49,416 KB |
testcase_03 | AC | 47 ms
49,360 KB |
testcase_04 | AC | 46 ms
49,412 KB |
testcase_05 | AC | 46 ms
49,552 KB |
testcase_06 | AC | 46 ms
49,360 KB |
testcase_07 | AC | 46 ms
49,456 KB |
testcase_08 | AC | 46 ms
49,496 KB |
testcase_09 | AC | 46 ms
49,616 KB |
testcase_10 | AC | 46 ms
49,540 KB |
testcase_11 | AC | 47 ms
50,064 KB |
testcase_12 | AC | 46 ms
49,452 KB |
testcase_13 | AC | 46 ms
49,728 KB |
testcase_14 | AC | 45 ms
49,436 KB |
testcase_15 | AC | 47 ms
49,452 KB |
testcase_16 | AC | 46 ms
49,452 KB |
testcase_17 | AC | 46 ms
49,392 KB |
testcase_18 | AC | 46 ms
49,400 KB |
testcase_19 | AC | 46 ms
47,420 KB |
testcase_20 | AC | 47 ms
50,224 KB |
testcase_21 | AC | 47 ms
50,244 KB |
testcase_22 | AC | 50 ms
50,088 KB |
testcase_23 | AC | 50 ms
50,064 KB |
testcase_24 | AC | 65 ms
51,464 KB |
testcase_25 | AC | 65 ms
51,204 KB |
testcase_26 | AC | 66 ms
51,148 KB |
testcase_27 | AC | 65 ms
50,492 KB |
testcase_28 | AC | 64 ms
50,376 KB |
testcase_29 | AC | 66 ms
50,828 KB |
testcase_30 | AC | 64 ms
48,576 KB |
testcase_31 | AC | 64 ms
50,516 KB |
testcase_32 | AC | 63 ms
50,376 KB |
testcase_33 | AC | 63 ms
50,668 KB |
testcase_34 | AC | 63 ms
50,608 KB |
testcase_35 | AC | 64 ms
50,596 KB |
testcase_36 | AC | 58 ms
50,392 KB |
testcase_37 | AC | 63 ms
50,772 KB |
testcase_38 | AC | 63 ms
50,956 KB |
testcase_39 | AC | 64 ms
50,784 KB |
testcase_40 | AC | 65 ms
50,696 KB |
testcase_41 | AC | 63 ms
51,296 KB |
testcase_42 | AC | 62 ms
51,248 KB |
testcase_43 | AC | 64 ms
51,224 KB |
testcase_44 | AC | 61 ms
50,968 KB |
testcase_45 | AC | 46 ms
49,904 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); } } }