結果

問題 No.106 素数が嫌い!2
ユーザー tsunabittsunabit
提出日時 2020-02-24 05:43:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 609 ms / 5,000 ms
コード長 1,020 bytes
コンパイル時間 3,265 ms
コンパイル使用メモリ 78,400 KB
実行使用メモリ 57,340 KB
最終ジャッジ日時 2024-04-19 14:50:49
合計ジャッジ時間 9,145 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 317 ms
48,356 KB
testcase_01 AC 115 ms
41,740 KB
testcase_02 AC 108 ms
41,344 KB
testcase_03 AC 113 ms
41,544 KB
testcase_04 AC 311 ms
48,104 KB
testcase_05 AC 588 ms
57,340 KB
testcase_06 AC 598 ms
56,952 KB
testcase_07 AC 593 ms
57,036 KB
testcase_08 AC 173 ms
42,428 KB
testcase_09 AC 168 ms
42,452 KB
testcase_10 AC 609 ms
56,612 KB
testcase_11 AC 279 ms
46,320 KB
testcase_12 AC 575 ms
56,396 KB
testcase_13 AC 119 ms
41,592 KB
testcase_14 AC 122 ms
41,448 KB
testcase_15 AC 121 ms
41,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class No106 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		// 素数を列挙
		List<Integer> list = new ArrayList<Integer>();
		for(int i = 2; i <= n; i++) {
			if(isPrime(i)) {
				list.add(i);
			}
		}
		int[] a = new int[n+1];
		Arrays.fill(a, 0);
		for(int t : list) {
			int b = 1;
			int temp = t;
			while(temp <= n) {
				a[temp] += 1;
				b++;
				temp = t * b;
			}
		}
		int ans = 0;
		for(int i = 0; i < a.length; i++) {
			if(a[i] >= k) ans++;
		}
		System.out.println(ans);
	}
	
	public static boolean isPrime(int num) {
        if (num < 2) return false;
        else if (num == 2) return true;
        else if (num % 2 == 0) return false;
        
        double sqrtNum = Math.sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
}
0