結果

問題 No.300 平方数
ユーザー kou6839kou6839
提出日時 2015-11-15 13:43:16
言語 Java
(openjdk 23)
結果
AC  
実行時間 148 ms / 1,000 ms
コード長 560 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 76,048 KB
実行使用メモリ 54,448 KB
最終ジャッジ日時 2024-09-13 15:02:08
合計ジャッジ時間 9,776 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #


import java.nio.channels.AsynchronousServerSocketChannel;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		long n = sc.nextLong();
		
		HashMap<Long, Integer> map = new HashMap<>();
		
		for(long i=2;i*i<=n;i++){
			while(n%i==0){
				n/=i;
				if(map.containsKey(i)){
					map.put(i, map.get(i)+1);
				}else{
					map.put(i,1);
				}
			}
		}
		long ans = 1;
		for(long l : map.keySet()){
			if(map.get(l)%2!=0) ans*=l;
		}
		if(n!=1) ans*=n;
		System.out.println(ans);
	}
}
0