結果

問題 No.300 平方数
ユーザー hhgfhn1hhgfhn1
提出日時 2018-11-03 21:46:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 903 ms / 1,000 ms
コード長 718 bytes
コンパイル時間 2,421 ms
コンパイル使用メモリ 76,848 KB
実行使用メモリ 139,540 KB
最終ジャッジ日時 2024-04-30 21:33:57
合計ジャッジ時間 26,647 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
53,960 KB
testcase_01 AC 139 ms
54,036 KB
testcase_02 AC 602 ms
114,544 KB
testcase_03 AC 141 ms
54,060 KB
testcase_04 AC 143 ms
53,956 KB
testcase_05 AC 139 ms
53,940 KB
testcase_06 AC 144 ms
54,120 KB
testcase_07 AC 142 ms
54,164 KB
testcase_08 AC 139 ms
54,084 KB
testcase_09 AC 141 ms
54,188 KB
testcase_10 AC 139 ms
54,232 KB
testcase_11 AC 141 ms
54,384 KB
testcase_12 AC 193 ms
54,716 KB
testcase_13 AC 837 ms
139,504 KB
testcase_14 AC 247 ms
61,868 KB
testcase_15 AC 527 ms
104,300 KB
testcase_16 AC 494 ms
91,300 KB
testcase_17 AC 830 ms
139,400 KB
testcase_18 AC 242 ms
61,796 KB
testcase_19 AC 453 ms
84,336 KB
testcase_20 AC 344 ms
74,988 KB
testcase_21 AC 832 ms
139,540 KB
testcase_22 AC 762 ms
127,220 KB
testcase_23 AC 741 ms
124,424 KB
testcase_24 AC 551 ms
108,160 KB
testcase_25 AC 724 ms
122,760 KB
testcase_26 AC 684 ms
118,032 KB
testcase_27 AC 528 ms
104,448 KB
testcase_28 AC 714 ms
121,940 KB
testcase_29 AC 794 ms
129,424 KB
testcase_30 AC 795 ms
130,472 KB
testcase_31 AC 903 ms
137,592 KB
testcase_32 AC 554 ms
110,312 KB
testcase_33 AC 425 ms
81,684 KB
testcase_34 AC 779 ms
127,964 KB
testcase_35 AC 555 ms
110,464 KB
testcase_36 AC 591 ms
116,336 KB
testcase_37 AC 549 ms
108,468 KB
testcase_38 AC 584 ms
114,612 KB
testcase_39 AC 693 ms
118,772 KB
testcase_40 AC 590 ms
114,316 KB
testcase_41 AC 378 ms
79,732 KB
testcase_42 AC 550 ms
108,316 KB
testcase_43 AC 847 ms
128,400 KB
testcase_44 AC 594 ms
116,512 KB
testcase_45 AC 437 ms
82,932 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++;
			}
			map.put((long) i, cnt);
		}
		map.put(x, 1);
		return map;
	}
}
0