結果
問題 |
No.371 ぼく悪いプライムじゃないよ
|
ユーザー |
![]() |
提出日時 | 2020-02-13 15:54:04 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 139 ms / 1,000 ms |
コード長 | 1,027 bytes |
コンパイル時間 | 1,976 ms |
コンパイル使用メモリ | 74,856 KB |
実行使用メモリ | 41,476 KB |
最終ジャッジ日時 | 2024-10-06 02:26:52 |
合計ジャッジ時間 | 8,168 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 42 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long low = sc.nextLong(); long high = sc.nextLong(); long maxNumber = high / 2 * 2; for (long i = (long)(Math.sqrt(high)); i >= 3 ; i--) { if (!isPrime(i)) { continue; } for (long j = high / i * i; j >= low; j -= i) { if (getMax(j) >= i) { System.out.println(j); return; } } } System.out.println(maxNumber); } static long getMax(long x) { for (long i = 2; i <= Math.sqrt(x); i++) { if (x % i == 0) { return i; } } return x; } static boolean isPrime(long x) { for (long i = 2; i <= Math.sqrt(x); i++) { if (x % i == 0) { return false; } } return true; } }