結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー tentententen
提出日時 2023-07-27 16:21:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 121 ms / 1,000 ms
コード長 1,896 bytes
コンパイル時間 3,167 ms
コンパイル使用メモリ 95,044 KB
実行使用メモリ 43,052 KB
最終ジャッジ日時 2024-04-15 03:38:52
合計ジャッジ時間 6,421 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
36,884 KB
testcase_01 AC 56 ms
37,060 KB
testcase_02 AC 56 ms
37,024 KB
testcase_03 AC 68 ms
37,520 KB
testcase_04 AC 57 ms
37,060 KB
testcase_05 AC 56 ms
37,272 KB
testcase_06 AC 59 ms
36,884 KB
testcase_07 AC 57 ms
37,332 KB
testcase_08 AC 57 ms
37,204 KB
testcase_09 AC 59 ms
37,256 KB
testcase_10 AC 56 ms
37,080 KB
testcase_11 AC 57 ms
36,764 KB
testcase_12 AC 58 ms
37,204 KB
testcase_13 AC 56 ms
37,252 KB
testcase_14 AC 56 ms
37,204 KB
testcase_15 AC 57 ms
37,316 KB
testcase_16 AC 57 ms
37,184 KB
testcase_17 AC 57 ms
37,264 KB
testcase_18 AC 57 ms
37,272 KB
testcase_19 AC 77 ms
38,564 KB
testcase_20 AC 84 ms
39,564 KB
testcase_21 AC 56 ms
37,224 KB
testcase_22 AC 56 ms
37,112 KB
testcase_23 AC 59 ms
37,120 KB
testcase_24 AC 56 ms
37,232 KB
testcase_25 AC 92 ms
40,488 KB
testcase_26 AC 56 ms
37,012 KB
testcase_27 AC 57 ms
37,196 KB
testcase_28 AC 57 ms
36,896 KB
testcase_29 AC 57 ms
37,204 KB
testcase_30 AC 57 ms
36,892 KB
testcase_31 AC 56 ms
37,020 KB
testcase_32 AC 81 ms
39,252 KB
testcase_33 AC 115 ms
42,872 KB
testcase_34 AC 121 ms
43,052 KB
testcase_35 AC 92 ms
40,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int length = sc.nextInt();
        int size = length / (n - 1);
        boolean[] isNotPrimes = new boolean[size + 1];
        long ans = 0;
        for (int i = 2; i <= size; i++) {
            if (!isNotPrimes[i]) {
                ans += length - (n - 1) * i + 1;
                for (int j = 2; j * i <= size; j++) {
                    isNotPrimes[j * i] = true;
                }
            }
        }
        System.out.println(ans);
    }
} 
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0