結果

問題 No.106 素数が嫌い!2
ユーザー scachescache
提出日時 2014-11-19 15:47:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 307 ms / 5,000 ms
コード長 1,126 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 74,060 KB
実行使用メモリ 62,500 KB
最終ジャッジ日時 2023-08-30 21:52:35
合計ジャッジ時間 6,565 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 216 ms
60,128 KB
testcase_01 AC 118 ms
55,744 KB
testcase_02 AC 118 ms
56,244 KB
testcase_03 AC 117 ms
56,448 KB
testcase_04 AC 215 ms
60,356 KB
testcase_05 AC 307 ms
62,060 KB
testcase_06 AC 304 ms
62,500 KB
testcase_07 AC 303 ms
61,704 KB
testcase_08 AC 143 ms
56,280 KB
testcase_09 AC 146 ms
55,412 KB
testcase_10 AC 307 ms
61,764 KB
testcase_11 AC 208 ms
58,312 KB
testcase_12 AC 301 ms
61,856 KB
testcase_13 AC 119 ms
55,844 KB
testcase_14 AC 119 ms
56,180 KB
testcase_15 AC 118 ms
55,400 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) {
		if(n>2000000 || n<2){
			System.out.println("wrong input");
			System.exit(1);
			
		}
		
		if(k>100 || k<1){
			System.out.println("wrong input");
			System.exit(1);
		}
		
		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