結果

問題 No.414 衝動
ユーザー hhgfhn1hhgfhn1
提出日時 2018-11-03 23:01:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 195 ms / 1,000 ms
コード長 881 bytes
コンパイル時間 2,363 ms
コンパイル使用メモリ 83,752 KB
実行使用メモリ 55,212 KB
最終ジャッジ日時 2024-04-27 08:36:27
合計ジャッジ時間 5,562 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 174 ms
55,056 KB
testcase_01 AC 158 ms
55,028 KB
testcase_02 AC 158 ms
54,880 KB
testcase_03 AC 173 ms
54,932 KB
testcase_04 AC 177 ms
54,832 KB
testcase_05 AC 177 ms
55,056 KB
testcase_06 AC 176 ms
55,212 KB
testcase_07 AC 180 ms
55,084 KB
testcase_08 AC 188 ms
55,096 KB
testcase_09 AC 195 ms
55,108 KB
testcase_10 AC 177 ms
55,120 KB
testcase_11 AC 180 ms
55,128 KB
testcase_12 AC 159 ms
55,168 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 m=scanner.nextLong();
		Map<Long,Integer>map=prime_fact(m);
		int i=0;
		long a=1;
		long b=1;
		for(long l:map.keySet()) {
			a=l;
			break;
		}
		for(long l:map.keySet()) {
			if(i==0) {
				b*=Math.pow(l, map.get(l)-1);
				i++;
				continue;
			}
			b*=Math.pow(l, map.get(l));
		}
		System.out.println(a+" "+b);
	}
	
	private static Map<Long, Integer> prime_fact(long n) {
		Map<Long, Integer> map = new TreeMap<>();
		double d = Math.sqrt(n);
		for (int i = 2; i <= d; i++) {
			int cnt = 0;
			while (n % i == 0) {
				n /= i;
				cnt++;
			}
			if (cnt != 0) {
				map.put((long) i, cnt);
			}
		}
		if (n != 1) {
			map.put(n, 1);
		}
		return map;
	}
}
0