結果

問題 No.106 素数が嫌い!2
ユーザー scachescache
提出日時 2014-11-19 15:37:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 305 ms / 5,000 ms
コード長 939 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 73,860 KB
実行使用メモリ 62,696 KB
最終ジャッジ日時 2023-08-30 21:52:28
合計ジャッジ時間 6,375 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 215 ms
60,360 KB
testcase_01 AC 118 ms
56,092 KB
testcase_02 AC 117 ms
56,148 KB
testcase_03 AC 118 ms
55,684 KB
testcase_04 AC 215 ms
60,392 KB
testcase_05 AC 302 ms
62,696 KB
testcase_06 AC 305 ms
62,648 KB
testcase_07 AC 304 ms
62,212 KB
testcase_08 AC 142 ms
55,980 KB
testcase_09 AC 144 ms
56,140 KB
testcase_10 AC 303 ms
62,336 KB
testcase_11 AC 210 ms
58,048 KB
testcase_12 AC 299 ms
61,920 KB
testcase_13 AC 119 ms
55,620 KB
testcase_14 AC 120 ms
56,468 KB
testcase_15 AC 118 ms
56,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	public static void main(String[] args) {
		Main p = new Main();
	}

	public Main() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		System.out.println(solve(n, k));
	}

	public int solve(int n, int k) {
		int[] sieve = new int[n+1];
		Arrays.fill(sieve, Integer.MAX_VALUE);
		
		for(int i=2;i<sieve.length;i++){
			if(sieve[i] != Integer.MAX_VALUE)
				continue;
			
			for(int j=i;j<sieve.length;j+=i)
				if(sieve[j] == Integer.MAX_VALUE)
					sieve[j] = i;
		}
		
		int res = 0;
		for(int i=2;i<sieve.length;i++){
			int cur = i;
			int count = 0;
			while(cur > 1){
				int j = sieve[cur];
				while(cur%j==0)
					cur /= j;
				
				count++;
			}
			
			if(count>=k)
				res++;
//			System.out.println(String.format("%6d : %3d", i, count));
		}
		
		return res;
	}

}
0