結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー tentententen
提出日時 2021-11-02 09:34:46
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,622 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 78,104 KB
実行使用メモリ 50,468 KB
最終ジャッジ日時 2024-04-19 15:30:59
合計ジャッジ時間 4,359 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
36,684 KB
testcase_01 AC 48 ms
37,180 KB
testcase_02 AC 90 ms
39,996 KB
testcase_03 AC 50 ms
37,040 KB
testcase_04 WA -
testcase_05 AC 48 ms
37,252 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 50 ms
37,064 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 50 ms
37,212 KB
testcase_12 AC 87 ms
40,028 KB
testcase_13 AC 77 ms
39,192 KB
testcase_14 AC 83 ms
39,916 KB
testcase_15 AC 86 ms
40,000 KB
testcase_16 AC 78 ms
39,952 KB
testcase_17 AC 71 ms
39,180 KB
testcase_18 AC 76 ms
39,108 KB
testcase_19 AC 85 ms
40,164 KB
testcase_20 AC 76 ms
39,684 KB
testcase_21 AC 88 ms
40,044 KB
testcase_22 AC 78 ms
40,392 KB
testcase_23 AC 84 ms
40,204 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++;
            }
        }
        if (left < right) {
            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