結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー tentententen
提出日時 2022-10-13 08:41:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 97 ms / 1,000 ms
コード長 1,383 bytes
コンパイル時間 2,411 ms
コンパイル使用メモリ 74,080 KB
実行使用メモリ 54,636 KB
最終ジャッジ日時 2023-09-08 18:51:43
合計ジャッジ時間 6,170 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,128 KB
testcase_01 AC 42 ms
47,656 KB
testcase_02 AC 43 ms
49,476 KB
testcase_03 AC 50 ms
49,400 KB
testcase_04 AC 43 ms
49,124 KB
testcase_05 AC 43 ms
49,216 KB
testcase_06 AC 43 ms
49,480 KB
testcase_07 AC 43 ms
49,460 KB
testcase_08 AC 43 ms
49,264 KB
testcase_09 AC 43 ms
49,468 KB
testcase_10 AC 43 ms
49,116 KB
testcase_11 AC 43 ms
49,244 KB
testcase_12 AC 43 ms
49,720 KB
testcase_13 AC 43 ms
49,424 KB
testcase_14 AC 43 ms
49,432 KB
testcase_15 AC 43 ms
49,324 KB
testcase_16 AC 43 ms
49,304 KB
testcase_17 AC 43 ms
49,472 KB
testcase_18 AC 43 ms
49,332 KB
testcase_19 AC 58 ms
50,272 KB
testcase_20 AC 68 ms
50,640 KB
testcase_21 AC 44 ms
49,240 KB
testcase_22 AC 44 ms
49,164 KB
testcase_23 AC 44 ms
49,200 KB
testcase_24 AC 44 ms
49,240 KB
testcase_25 AC 77 ms
52,672 KB
testcase_26 AC 44 ms
49,344 KB
testcase_27 AC 43 ms
49,328 KB
testcase_28 AC 43 ms
49,432 KB
testcase_29 AC 42 ms
49,260 KB
testcase_30 AC 43 ms
49,728 KB
testcase_31 AC 43 ms
49,628 KB
testcase_32 AC 65 ms
50,652 KB
testcase_33 AC 95 ms
54,628 KB
testcase_34 AC 97 ms
54,636 KB
testcase_35 AC 73 ms
52,480 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();
        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 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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0