結果

問題 No.442 和と積
ユーザー tentententen
提出日時 2022-08-02 08:59:50
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,139 bytes
コンパイル時間 5,226 ms
コンパイル使用メモリ 75,284 KB
実行使用メモリ 55,856 KB
最終ジャッジ日時 2023-09-30 07:33:45
合計ジャッジ時間 9,802 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
38,000 KB
testcase_01 AC 36 ms
33,620 KB
testcase_02 AC 35 ms
33,228 KB
testcase_03 AC 51 ms
35,028 KB
testcase_04 AC 35 ms
33,752 KB
testcase_05 AC 36 ms
33,316 KB
testcase_06 AC 36 ms
33,328 KB
testcase_07 AC 51 ms
34,776 KB
testcase_08 AC 37 ms
33,368 KB
testcase_09 AC 70 ms
35,892 KB
testcase_10 AC 37 ms
33,700 KB
testcase_11 AC 37 ms
33,272 KB
testcase_12 AC 37 ms
33,252 KB
testcase_13 AC 37 ms
33,616 KB
testcase_14 AC 36 ms
33,304 KB
testcase_15 AC 41 ms
33,772 KB
testcase_16 AC 40 ms
33,508 KB
testcase_17 AC 37 ms
33,776 KB
testcase_18 AC 39 ms
33,328 KB
testcase_19 AC 54 ms
34,596 KB
testcase_20 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
}
0