結果

問題 No.1737 One to N
ユーザー ks2mks2m
提出日時 2021-11-12 21:33:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 817 bytes
コンパイル時間 2,012 ms
コンパイル使用メモリ 78,716 KB
実行使用メモリ 41,764 KB
最終ジャッジ日時 2024-05-04 05:09:38
合計ジャッジ時間 6,290 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
41,416 KB
testcase_01 AC 110 ms
41,252 KB
testcase_02 AC 106 ms
41,396 KB
testcase_03 AC 106 ms
41,436 KB
testcase_04 AC 104 ms
41,424 KB
testcase_05 AC 118 ms
41,216 KB
testcase_06 AC 105 ms
41,640 KB
testcase_07 AC 115 ms
40,172 KB
testcase_08 AC 103 ms
41,536 KB
testcase_09 AC 112 ms
41,160 KB
testcase_10 AC 117 ms
41,248 KB
testcase_11 AC 117 ms
41,404 KB
testcase_12 AC 112 ms
41,424 KB
testcase_13 AC 117 ms
41,764 KB
testcase_14 AC 116 ms
41,164 KB
testcase_15 AC 113 ms
41,452 KB
testcase_16 AC 106 ms
41,284 KB
testcase_17 AC 117 ms
41,740 KB
testcase_18 AC 116 ms
41,752 KB
testcase_19 AC 100 ms
41,548 KB
testcase_20 AC 107 ms
41,268 KB
testcase_21 AC 115 ms
41,344 KB
testcase_22 AC 121 ms
41,628 KB
testcase_23 AC 120 ms
41,404 KB
testcase_24 AC 115 ms
41,456 KB
testcase_25 AC 107 ms
41,184 KB
testcase_26 AC 100 ms
41,720 KB
testcase_27 AC 105 ms
41,420 KB
testcase_28 AC 106 ms
41,528 KB
testcase_29 AC 109 ms
41,504 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