結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー tentententen
提出日時 2020-09-11 18:38:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 788 ms / 1,000 ms
コード長 711 bytes
コンパイル時間 2,142 ms
コンパイル使用メモリ 72,896 KB
実行使用メモリ 63,028 KB
最終ジャッジ日時 2023-08-27 03:11:29
合計ジャッジ時間 10,581 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
53,500 KB
testcase_01 AC 126 ms
55,548 KB
testcase_02 AC 125 ms
55,716 KB
testcase_03 AC 161 ms
54,416 KB
testcase_04 AC 126 ms
56,188 KB
testcase_05 AC 124 ms
55,864 KB
testcase_06 AC 128 ms
55,532 KB
testcase_07 AC 127 ms
55,592 KB
testcase_08 AC 125 ms
55,328 KB
testcase_09 AC 125 ms
55,944 KB
testcase_10 AC 126 ms
55,892 KB
testcase_11 AC 126 ms
55,680 KB
testcase_12 AC 126 ms
55,860 KB
testcase_13 AC 126 ms
55,664 KB
testcase_14 AC 127 ms
55,776 KB
testcase_15 AC 123 ms
55,632 KB
testcase_16 AC 125 ms
55,636 KB
testcase_17 AC 124 ms
55,520 KB
testcase_18 AC 125 ms
55,644 KB
testcase_19 AC 192 ms
57,988 KB
testcase_20 AC 294 ms
60,556 KB
testcase_21 AC 125 ms
55,328 KB
testcase_22 AC 124 ms
55,916 KB
testcase_23 AC 125 ms
55,788 KB
testcase_24 AC 124 ms
56,100 KB
testcase_25 AC 418 ms
60,416 KB
testcase_26 AC 125 ms
55,864 KB
testcase_27 AC 126 ms
55,328 KB
testcase_28 AC 126 ms
55,484 KB
testcase_29 AC 123 ms
55,708 KB
testcase_30 AC 125 ms
55,840 KB
testcase_31 AC 128 ms
55,792 KB
testcase_32 AC 259 ms
58,272 KB
testcase_33 AC 788 ms
63,028 KB
testcase_34 AC 788 ms
62,752 KB
testcase_35 AC 383 ms
60,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
	}
}
0