結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー tentententen
提出日時 2022-08-01 19:07:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 95 ms / 1,000 ms
コード長 1,351 bytes
コンパイル時間 1,713 ms
コンパイル使用メモリ 74,056 KB
実行使用メモリ 55,320 KB
最終ジャッジ日時 2023-09-29 15:48:52
合計ジャッジ時間 5,399 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
49,196 KB
testcase_01 AC 35 ms
49,184 KB
testcase_02 AC 36 ms
49,376 KB
testcase_03 AC 51 ms
50,928 KB
testcase_04 AC 36 ms
49,208 KB
testcase_05 AC 59 ms
54,948 KB
testcase_06 AC 66 ms
53,012 KB
testcase_07 AC 39 ms
49,392 KB
testcase_08 AC 37 ms
49,256 KB
testcase_09 AC 37 ms
49,256 KB
testcase_10 AC 35 ms
47,824 KB
testcase_11 AC 37 ms
49,552 KB
testcase_12 AC 37 ms
49,264 KB
testcase_13 AC 37 ms
47,648 KB
testcase_14 AC 37 ms
49,648 KB
testcase_15 AC 37 ms
49,548 KB
testcase_16 AC 37 ms
49,372 KB
testcase_17 AC 36 ms
49,288 KB
testcase_18 AC 35 ms
49,296 KB
testcase_19 AC 53 ms
50,960 KB
testcase_20 AC 60 ms
50,712 KB
testcase_21 AC 35 ms
49,312 KB
testcase_22 AC 37 ms
49,304 KB
testcase_23 AC 52 ms
51,012 KB
testcase_24 AC 56 ms
50,428 KB
testcase_25 AC 74 ms
52,748 KB
testcase_26 AC 54 ms
52,856 KB
testcase_27 AC 36 ms
49,552 KB
testcase_28 AC 50 ms
50,816 KB
testcase_29 AC 55 ms
52,804 KB
testcase_30 AC 37 ms
49,524 KB
testcase_31 AC 57 ms
52,992 KB
testcase_32 AC 69 ms
52,844 KB
testcase_33 AC 85 ms
54,956 KB
testcase_34 AC 86 ms
55,024 KB
testcase_35 AC 95 ms
55,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int length = sc.nextInt();
        boolean[] isNotPrime = new boolean[length / 2 + 2];
        long ans = 0;
        for (int i = 2; i < isNotPrime.length && i * (n - 1) <= length; i++) {
            if (!isNotPrime[i]) {
                ans += length - i * (n - 1) + 1;
                for (int j = 2; j  * i < isNotPrime.length; j++) {
                    isNotPrime[j * i] = true;
                }
            }
        }
        System.out.println(ans);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0