結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー tentententen
提出日時 2023-02-15 11:34:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 98 ms / 1,000 ms
コード長 1,899 bytes
コンパイル時間 4,320 ms
コンパイル使用メモリ 85,168 KB
実行使用メモリ 55,000 KB
最終ジャッジ日時 2023-09-24 21:23:24
合計ジャッジ時間 6,147 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,452 KB
testcase_01 AC 45 ms
49,312 KB
testcase_02 AC 44 ms
49,448 KB
testcase_03 AC 51 ms
49,652 KB
testcase_04 AC 44 ms
49,476 KB
testcase_05 AC 44 ms
49,196 KB
testcase_06 AC 44 ms
49,420 KB
testcase_07 AC 44 ms
49,640 KB
testcase_08 AC 44 ms
49,280 KB
testcase_09 AC 46 ms
49,384 KB
testcase_10 AC 45 ms
49,304 KB
testcase_11 AC 45 ms
49,368 KB
testcase_12 AC 44 ms
49,588 KB
testcase_13 AC 44 ms
49,276 KB
testcase_14 AC 44 ms
49,328 KB
testcase_15 AC 45 ms
49,312 KB
testcase_16 AC 44 ms
49,292 KB
testcase_17 AC 44 ms
49,252 KB
testcase_18 AC 44 ms
49,300 KB
testcase_19 AC 61 ms
50,716 KB
testcase_20 AC 70 ms
50,620 KB
testcase_21 AC 44 ms
49,256 KB
testcase_22 AC 45 ms
49,384 KB
testcase_23 AC 45 ms
49,220 KB
testcase_24 AC 44 ms
49,192 KB
testcase_25 AC 78 ms
52,852 KB
testcase_26 AC 45 ms
49,352 KB
testcase_27 AC 44 ms
49,392 KB
testcase_28 AC 44 ms
49,636 KB
testcase_29 AC 44 ms
49,356 KB
testcase_30 AC 44 ms
49,300 KB
testcase_31 AC 45 ms
49,360 KB
testcase_32 AC 69 ms
50,564 KB
testcase_33 AC 98 ms
54,788 KB
testcase_34 AC 98 ms
55,000 KB
testcase_35 AC 78 ms
52,640 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 count = length / (n - 1);
        boolean[] isNotPrimes = new boolean[count + 1];
        long ans = 0;
        for (int i = 2; i <= count; i++) {
            if (!isNotPrimes[i]) {
                ans += length - (n - 1) * i + 1;
                for (int j = 2; j * i <= count; 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