結果

問題 No.826 連絡網
ユーザー tentententen
提出日時 2020-09-01 02:54:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 918 bytes
コンパイル時間 2,121 ms
コンパイル使用メモリ 74,816 KB
実行使用メモリ 42,164 KB
最終ジャッジ日時 2024-04-28 12:55:44
合計ジャッジ時間 8,341 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
41,616 KB
testcase_01 AC 133 ms
41,100 KB
testcase_02 AC 136 ms
41,488 KB
testcase_03 AC 137 ms
41,412 KB
testcase_04 AC 123 ms
40,344 KB
testcase_05 AC 135 ms
41,508 KB
testcase_06 AC 138 ms
40,948 KB
testcase_07 AC 137 ms
41,624 KB
testcase_08 AC 138 ms
41,456 KB
testcase_09 AC 147 ms
41,504 KB
testcase_10 AC 135 ms
41,196 KB
testcase_11 AC 124 ms
40,120 KB
testcase_12 AC 184 ms
42,164 KB
testcase_13 AC 160 ms
41,696 KB
testcase_14 AC 163 ms
40,936 KB
testcase_15 AC 152 ms
41,520 KB
testcase_16 AC 176 ms
41,440 KB
testcase_17 AC 161 ms
41,300 KB
testcase_18 AC 163 ms
41,288 KB
testcase_19 AC 189 ms
42,148 KB
testcase_20 AC 172 ms
42,100 KB
testcase_21 AC 140 ms
41,116 KB
testcase_22 AC 160 ms
41,636 KB
testcase_23 AC 161 ms
41,912 KB
testcase_24 AC 140 ms
40,488 KB
testcase_25 AC 197 ms
42,104 KB
testcase_26 AC 154 ms
41,572 KB
testcase_27 AC 181 ms
41,752 KB
testcase_28 AC 181 ms
41,528 KB
testcase_29 AC 163 ms
41,480 KB
testcase_30 AC 211 ms
41,936 KB
testcase_31 AC 146 ms
40,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static boolean[] used;
    static int n;
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	n = sc.nextInt();
    	used = new boolean[n + 1];
        int p = sc.nextInt();
        for (int i = 2; i <= Math.sqrt(p); i++) {
            if (p % i == 0) {
                setUse(i);
                p /= i;
                while (p % i == 0) {
                    p /= i;
                }
            }
        }
        if (p > 1) {
            setUse(p);
        }
        int count = 0;
        for (int i = 1; i <= n; i++) {
            if (used[i]) {
                count++;
            }
        }
    	System.out.println(count);
	}
	
	static void setUse(int x) {
	    if (used[x]) {
	        return;
	    }
	    used[x] = true;
	    for (int i = 2; i * x <= n; i++) {
	        used[i * x] = true;
	        setUse(i);
	    }
	}
}
0