結果

問題 No.1737 One to N
ユーザー ks2mks2m
提出日時 2021-11-12 21:33:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 817 bytes
コンパイル時間 2,268 ms
コンパイル使用メモリ 76,044 KB
実行使用メモリ 58,184 KB
最終ジャッジ日時 2023-08-16 21:47:50
合計ジャッジ時間 7,409 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
56,096 KB
testcase_01 AC 116 ms
56,272 KB
testcase_02 AC 116 ms
54,336 KB
testcase_03 AC 116 ms
55,876 KB
testcase_04 AC 117 ms
55,780 KB
testcase_05 AC 115 ms
56,244 KB
testcase_06 AC 117 ms
56,128 KB
testcase_07 AC 116 ms
55,888 KB
testcase_08 AC 116 ms
55,996 KB
testcase_09 AC 116 ms
56,392 KB
testcase_10 AC 118 ms
56,100 KB
testcase_11 AC 115 ms
56,420 KB
testcase_12 AC 116 ms
56,096 KB
testcase_13 AC 116 ms
56,444 KB
testcase_14 AC 115 ms
56,188 KB
testcase_15 AC 116 ms
56,004 KB
testcase_16 AC 117 ms
56,188 KB
testcase_17 AC 117 ms
56,008 KB
testcase_18 AC 116 ms
56,124 KB
testcase_19 AC 116 ms
55,584 KB
testcase_20 AC 118 ms
55,908 KB
testcase_21 AC 117 ms
56,304 KB
testcase_22 AC 118 ms
56,044 KB
testcase_23 AC 120 ms
55,884 KB
testcase_24 AC 117 ms
58,184 KB
testcase_25 AC 117 ms
56,236 KB
testcase_26 AC 116 ms
56,320 KB
testcase_27 AC 117 ms
56,212 KB
testcase_28 AC 118 ms
55,724 KB
testcase_29 AC 115 ms
56,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		if (n == 1) {
			System.out.println(0);
		} else {
			Map<Integer, Integer> soinsu = bunkai(n);
			int ans = 0;
			for (int k : soinsu.keySet()) {
				ans += k * soinsu.get(k);
			}
			System.out.println(ans);
		}
	}

	static Map<Integer, Integer> bunkai(int n) {
		Map<Integer, Integer> soinsu = new HashMap<>();
		int end = (int) Math.sqrt(n);
		int d = 2;
		while (n > 1) {
			if (n % d == 0) {
				n /= d;
				soinsu.put(d, soinsu.getOrDefault(d, 0) + 1);
				end = (int) Math.sqrt(n);
			} else {
				if (d > end) {
					d = n - 1;
				}
				d++;
			}
		}
		return soinsu;
	}
}
0