結果

問題 No.300 平方数
ユーザー hhgfhn1hhgfhn1
提出日時 2018-11-03 21:48:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 157 ms / 1,000 ms
コード長 740 bytes
コンパイル時間 2,496 ms
コンパイル使用メモリ 76,508 KB
実行使用メモリ 54,688 KB
最終ジャッジ日時 2024-04-30 21:34:09
合計ジャッジ時間 10,601 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
53,824 KB
testcase_01 AC 142 ms
54,044 KB
testcase_02 AC 154 ms
54,460 KB
testcase_03 AC 138 ms
54,196 KB
testcase_04 AC 139 ms
54,112 KB
testcase_05 AC 137 ms
54,212 KB
testcase_06 AC 139 ms
54,108 KB
testcase_07 AC 139 ms
54,688 KB
testcase_08 AC 136 ms
53,828 KB
testcase_09 AC 140 ms
54,224 KB
testcase_10 AC 136 ms
54,044 KB
testcase_11 AC 139 ms
54,448 KB
testcase_12 AC 140 ms
54,220 KB
testcase_13 AC 155 ms
54,208 KB
testcase_14 AC 144 ms
54,248 KB
testcase_15 AC 151 ms
54,080 KB
testcase_16 AC 150 ms
54,196 KB
testcase_17 AC 157 ms
54,368 KB
testcase_18 AC 142 ms
54,256 KB
testcase_19 AC 149 ms
54,240 KB
testcase_20 AC 147 ms
53,920 KB
testcase_21 AC 156 ms
54,096 KB
testcase_22 AC 153 ms
54,176 KB
testcase_23 AC 153 ms
54,204 KB
testcase_24 AC 149 ms
54,348 KB
testcase_25 AC 153 ms
53,896 KB
testcase_26 AC 151 ms
53,988 KB
testcase_27 AC 151 ms
53,900 KB
testcase_28 AC 152 ms
54,096 KB
testcase_29 AC 152 ms
54,244 KB
testcase_30 AC 152 ms
54,220 KB
testcase_31 AC 156 ms
54,236 KB
testcase_32 AC 148 ms
54,092 KB
testcase_33 AC 146 ms
54,264 KB
testcase_34 AC 152 ms
54,340 KB
testcase_35 AC 149 ms
54,168 KB
testcase_36 AC 151 ms
54,424 KB
testcase_37 AC 149 ms
54,288 KB
testcase_38 AC 145 ms
54,180 KB
testcase_39 AC 140 ms
53,144 KB
testcase_40 AC 149 ms
53,840 KB
testcase_41 AC 146 ms
54,356 KB
testcase_42 AC 150 ms
54,192 KB
testcase_43 AC 153 ms
54,364 KB
testcase_44 AC 150 ms
54,072 KB
testcase_45 AC 146 ms
54,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		long x = scanner.nextLong();
		Map<Long, Integer> map = prime_fact(x);
		long ans = 1;
		for (long key : map.keySet()) {
			if (map.get(key) % 2 == 1) {
				ans *= key;
			}
		}
		System.out.println(ans);
	}

	private static Map<Long, Integer> prime_fact(long x) {
		Map<Long, Integer> map = new TreeMap<>();
		double d = Math.sqrt(x);
		for (int i = 2; i <= d; i++) {
			int cnt = 0;
			while (x % i == 0) {
				x /= i;
				cnt++;
			}
			if(cnt!=0) {
				map.put((long) i, cnt);
			}
		}
		map.put(x, 1);
		return map;
	}
}
0