結果

問題 No.414 衝動
ユーザー hhgfhn1
提出日時 2018-11-03 22:59:58
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 892 bytes
コンパイル時間 2,881 ms
コンパイル使用メモリ 90,732 KB
実行使用メモリ 55,304 KB
最終ジャッジ日時 2024-11-20 19:38:35
合計ジャッジ時間 5,248 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12 WA * 1
権限があれば一括ダウンロードができます

ソースコード

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;
		int b=1;
		for(long l:map.keySet()) {
			a=l;
			break;
		}
		for(long l:map.keySet()) {
			if(i==0) {
				b*=(int) Math.pow(l, map.get(l)-1);
				i++;
				continue;
			}
			b*=(int) 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