結果
問題 |
No.407 鴨等素数間隔列の数え上げ
|
ユーザー |
![]() |
提出日時 | 2020-09-11 18:38:22 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 798 ms / 1,000 ms |
コード長 | 711 bytes |
コンパイル時間 | 3,147 ms |
コンパイル使用メモリ | 75,904 KB |
実行使用メモリ | 50,636 KB |
最終ジャッジ日時 | 2024-12-26 10:02:36 |
合計ジャッジ時間 | 11,824 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 31 |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int length = sc.nextInt(); ArrayList<Integer> primes = new ArrayList<>(); long ans = 0; for (int i = 2; i * (n - 1) <= length; i++) { if (isPrime(i, primes)) { primes.add(i); ans += length - i * (n - 1) + 1; } } System.out.println(ans); } static boolean isPrime(int x, ArrayList<Integer> primes) { for (int y : primes) { if (y * y > x) { break; } if (x % y == 0) { return false; } } return true; } }