結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー tenten
提出日時 2020-08-20 14:47:48
言語 Java
(openjdk 23)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 990 bytes
コンパイル時間 4,424 ms
コンパイル使用メモリ 79,644 KB
実行使用メモリ 42,344 KB
最終ジャッジ日時 2024-10-13 10:05:20
合計ジャッジ時間 6,427 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = n;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 2; i <= Math.sqrt(x); i++) {
            while (x % i == 0) {
                if (map.containsKey(i)) {
                    map.put(i, map.get(i) + 1);
                } else {
                    map.put(i, 1);
                }
                x /= i;
            }
        }
        if (x > 1) {
            if (map.containsKey(x)) {
                map.put(x, map.get(x) + 1);
            } else {
                map.put(x, 1);
            }
        }
        int ans = 1;
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            for (int i = 2; i <= entry.getValue(); i += 2) {
                ans *= entry.getKey();
            }
        }
        System.out.println(ans + " " + n / ans / ans);
    }
} 
0