結果

問題 No.3079 アルベド
ユーザー tentententen
提出日時 2022-11-07 16:08:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 1,489 bytes
コンパイル時間 2,252 ms
コンパイル使用メモリ 74,220 KB
実行使用メモリ 57,624 KB
最終ジャッジ日時 2023-09-28 05:16:48
合計ジャッジ時間 5,342 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,144 KB
testcase_01 AC 178 ms
57,356 KB
testcase_02 AC 150 ms
56,488 KB
testcase_03 AC 144 ms
57,624 KB
testcase_04 AC 162 ms
56,880 KB
testcase_05 AC 148 ms
56,204 KB
testcase_06 AC 160 ms
54,996 KB
testcase_07 AC 105 ms
52,744 KB
testcase_08 AC 119 ms
54,672 KB
testcase_09 AC 158 ms
57,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int t = sc.nextInt();
        boolean[] isNotPrimes = new boolean[100001];
        int[] counts = new int[100001];
        for (int i = 2; i <= 100000; i++) {
            counts[i] = counts[i - 1];
            if (!isNotPrimes[i]) {
                counts[i]++;
                for (int j = 2; j * i <= 100000; j++) {
                    isNotPrimes[j * i] = true;
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        while (t-- > 0) {
            sb.append(counts[sc.nextInt()]).append("\n");
        }
        System.out.print(sb);
    }
}
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