結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー ks2mks2m
提出日時 2020-05-29 21:26:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 888 bytes
コンパイル時間 2,765 ms
コンパイル使用メモリ 80,124 KB
実行使用メモリ 55,108 KB
最終ジャッジ日時 2024-04-23 20:09:50
合計ジャッジ時間 6,801 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
54,812 KB
testcase_01 AC 158 ms
55,108 KB
testcase_02 AC 147 ms
54,652 KB
testcase_03 AC 158 ms
55,032 KB
testcase_04 AC 156 ms
55,044 KB
testcase_05 AC 162 ms
55,024 KB
testcase_06 AC 159 ms
49,128 KB
testcase_07 AC 159 ms
50,856 KB
testcase_08 AC 158 ms
51,124 KB
testcase_09 AC 155 ms
51,072 KB
testcase_10 AC 159 ms
50,584 KB
testcase_11 AC 157 ms
51,060 KB
testcase_12 AC 159 ms
51,060 KB
testcase_13 AC 159 ms
50,840 KB
testcase_14 AC 160 ms
50,988 KB
testcase_15 AC 160 ms
51,020 KB
testcase_16 AC 158 ms
50,800 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();

		Map<Integer, Integer> map = bunkai(n);
		int a = 1;
		int b = 1;
		for (int k : map.keySet()) {
			a *= (int) Math.pow(k, map.get(k) / 2);
			b *= (int) Math.pow(k, map.get(k) % 2);
		}
		System.out.println(a + " " + b);
	}

	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;
				if (soinsu.containsKey(d)) {
					soinsu.put(d, soinsu.get(d) + 1);
				} else {
					soinsu.put(d, 1);
				}
				end = (int) Math.sqrt(n);
			} else {
				if (d > end) {
					d = n - 1;
				}
				d++;
			}
		}
		return soinsu;
	}
}
0