結果
| 問題 | No.442 和と積 |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-08-02 08:59:50 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,139 bytes |
| 記録 | |
| コンパイル時間 | 2,919 ms |
| コンパイル使用メモリ | 78,584 KB |
| 実行使用メモリ | 45,616 KB |
| 最終ジャッジ日時 | 2024-07-23 01:48:41 |
| 合計ジャッジ時間 | 6,643 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 TLE * 1 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
long a = sc.nextLong();
long b = sc.nextLong();
long c = a + b;
HashMap<Long, Integer> base = new HashMap<>();
for (long i = 2; i <= Math.sqrt(c); i++) {
while (c % i == 0) {
base.put(i, base.getOrDefault(i, 0) + 1);
c /= i;
}
}
if (c > 1) {
base.put(c, base.getOrDefault(c, 0) + 1);
}
HashMap<Long, Integer> next = new HashMap<>();
for (long i = 2; i <= Math.sqrt(a); i++) {
while (a % i == 0) {
next.put(i, next.getOrDefault(i, 0) + 1);
a /= i;
}
}
if (a > 1) {
next.put(a, next.getOrDefault(a, 0) + 1);
}
for (long i = 2; i <= Math.sqrt(b); i++) {
while (b % i == 0) {
next.put(i, next.getOrDefault(i, 0) + 1);
b /= i;
}
}
if (b > 1) {
next.put(b, next.getOrDefault(b, 0) + 1);
}
long ans = 1;
for (long x : base.keySet()) {
int times = Math.min(base.get(x), next.getOrDefault(x, 0));
for (int i = 0; i < times; i++) {
ans *= x;
}
}
System.out.println(ans);
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public String next() throws Exception {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten