結果

問題 No.300 平方数
ユーザー tentententen
提出日時 2020-10-07 09:14:33
言語 Java
(openjdk 23)
結果
AC  
実行時間 157 ms / 1,000 ms
コード長 764 bytes
コンパイル時間 2,679 ms
コンパイル使用メモリ 76,716 KB
実行使用メモリ 54,360 KB
最終ジャッジ日時 2024-07-20 03:16:04
合計ジャッジ時間 10,416 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		HashMap<Long, Integer> map = new HashMap<>();
		for (long 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);
		    }
		}
		long ans = 1;
		for (Map.Entry<Long, Integer> entry : map.entrySet()) {
		    if (entry.getValue() % 2 == 1) {
		        ans *= entry.getKey();
		    }
		}
		System.out.println(ans);
	}
}
0