結果

問題 No.106 素数が嫌い!2
ユーザー YamaKasaYamaKasa
提出日時 2018-07-07 18:06:40
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 909 bytes
コンパイル時間 4,103 ms
コンパイル使用メモリ 79,268 KB
実行使用メモリ 67,104 KB
最終ジャッジ日時 2023-09-18 10:00:36
合計ジャッジ時間 19,896 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 128 ms
56,076 KB
testcase_02 AC 129 ms
55,876 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2,125 ms
67,104 KB
testcase_07 AC 2,126 ms
66,924 KB
testcase_08 WA -
testcase_09 AC 215 ms
55,744 KB
testcase_10 AC 2,127 ms
66,960 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 130 ms
55,848 KB
testcase_14 AC 126 ms
55,728 KB
testcase_15 AC 132 ms
55,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		scan.close();
		ArrayList<Integer> list = new ArrayList<Integer>();
		int []n = new int[N + 1];
		Arrays.fill(n, 0);
		for(int i = 2; i <= N; i++) {
			if(isPrime(i)) {
				list.add(i);
			}
		}
		for(int i : list) {
			int j = 1;
			while(i * j <= N) {
				n[i * j] ++;
				j ++;
			}
		}
//		for(int i : list) {
//			System.out.println(i);
//		}
		int cnt = 0;
		for(int i = 2; i <= N; i++) {
			if(n[i] == K) {
				cnt++;
			}
		}
		System.out.println(cnt);


	}
	public static boolean isPrime(long n) {
        for(long i = 2; i <= (int)Math.sqrt(n); i++){
            if(n % i == 0) {
               return false;
            }
        }
        return true;
    }

}
0