結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー tentententen
提出日時 2021-11-02 09:33:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,564 bytes
コンパイル時間 2,383 ms
コンパイル使用メモリ 77,348 KB
実行使用メモリ 40,136 KB
最終ジャッジ日時 2024-04-19 15:29:40
合計ジャッジ時間 5,271 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
36,936 KB
testcase_01 AC 46 ms
36,460 KB
testcase_02 AC 96 ms
39,792 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 47 ms
37,028 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 51 ms
36,880 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 55 ms
36,540 KB
testcase_12 AC 95 ms
39,868 KB
testcase_13 AC 80 ms
38,944 KB
testcase_14 AC 96 ms
39,648 KB
testcase_15 AC 97 ms
39,584 KB
testcase_16 AC 86 ms
38,820 KB
testcase_17 AC 76 ms
38,892 KB
testcase_18 AC 88 ms
38,884 KB
testcase_19 AC 94 ms
39,816 KB
testcase_20 AC 89 ms
39,312 KB
testcase_21 AC 98 ms
40,068 KB
testcase_22 AC 86 ms
40,136 KB
testcase_23 AC 95 ms
39,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int left = sc.nextInt();
        int right = sc.nextInt();
        int size = right * 2 + 2;
        boolean[] isNotPrime = new boolean[size];
        for (int i = 2; i < size; i++) {
            if (isNotPrime[i]) {
                continue;
            }
            for (int j = 2; j * i < size; j++) {
                isNotPrime[j * i] = true;
            }
        }
        int count = 0;
        for (int i = Math.max(2, left); i <= right; i++)  {
            if (!isNotPrime[i]) {
                count++;
            }
        }
        for (int i = left * 2 + 1; i <= right * 2 + 1; i += 2) {
            if (!isNotPrime[i]) {
                count++;
            }
        }
        System.out.println(count);
    }
}
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 String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0