結果

問題 No.442 和と積
ユーザー tentententen
提出日時 2022-08-01 19:49:48
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,139 bytes
コンパイル時間 4,745 ms
コンパイル使用メモリ 74,704 KB
実行使用メモリ 56,736 KB
最終ジャッジ日時 2023-09-29 16:33:59
合計ジャッジ時間 9,368 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
52,864 KB
testcase_01 AC 43 ms
49,212 KB
testcase_02 AC 43 ms
49,228 KB
testcase_03 AC 57 ms
51,036 KB
testcase_04 AC 43 ms
49,260 KB
testcase_05 AC 42 ms
49,136 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 72 ms
52,316 KB
testcase_10 AC 44 ms
49,208 KB
testcase_11 AC 44 ms
49,368 KB
testcase_12 AC 43 ms
47,200 KB
testcase_13 AC 44 ms
49,184 KB
testcase_14 AC 46 ms
49,104 KB
testcase_15 AC 48 ms
49,744 KB
testcase_16 AC 46 ms
49,532 KB
testcase_17 AC 44 ms
49,232 KB
testcase_18 AC 45 ms
49,264 KB
testcase_19 AC 61 ms
50,928 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(c, 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(c, 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