結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー ks2m
提出日時 2020-05-29 21:26:48
言語 Java
(openjdk 23)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 888 bytes
コンパイル時間 3,893 ms
コンパイル使用メモリ 83,224 KB
実行使用メモリ 55,116 KB
最終ジャッジ日時 2024-11-06 02:26:43
合計ジャッジ時間 6,131 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

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