Problem:
Score : 300 points

Problem Statement

Takahashi is organizing a party.

At the party, each guest will receive one or more snack pieces.

Takahashi predicts that the number of guests at this party will be A or B.

Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted.

We assume that a piece cannot be divided and distributed to multiple guests.

Constraints

1 \leq A, B \leq 10^5

A \neq B

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the minimum number of pieces that can be evenly distributed to the guests in both of the cases with A guests and B guests.

Sample Input 1

2 3

Sample Output 1

6

When we have six snack pieces, each guest can take three pieces if we have two guests, and each guest can take two if we have three guests.

Sample Input 2

123 456

Sample Output 2

18696

Sample Input 3

100000 99999

Sample Output 3

9999900000

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        Set<Integer> primeNumberSet = primeNumberSet(Math.max(a, b));
        Map<Integer, Integer> divisorSetA = getDivisorList(a, primeNumberSet);
        Map<Integer, Integer> divisorSetB = getDivisorList(b, primeNumberSet);
        divisorSetB.keySet().forEach(k -> divisorSetA.put(k, Math.max(divisorSetB.get(k), divisorSetA.getOrDefault(k, 0))));
        List<Integer> list = divisorSetA.keySet().stream().map(k -> (int) Math.pow(k, divisorSetA.get(k))).collect(Collectors.toList());
        long n = 1;
        for (int num : list) {
            n = n * num;
        }
        System.out.println(n);
    }

    static Map<Integer, Integer> getDivisorList(int n, Set<Integer> primeNumberSet) {
        return primeNumberSet.stream().filter(f -> f <= n).filter(m -> n % m == 0).collect(Collectors.toMap(m -> m, m -> count(n, m)));
    }

    static Set<Integer> primeNumberSet(int n) {
        if (n < 2) return new HashSet<>();
        return IntStream.rangeClosed(2, n).filter(Main::isPrimeNumber).boxed().collect(Collectors.toSet());
    }

    static boolean isPrimeNumber(int n) {
        if (n == 2) return true;
        if (n % 2 == 0) return false;
        for (int i = 3; i <= Math.sqrt(n); i += 2) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }

    static int count(int m, int n) {
        int count = 0;
        while (m % n == 0) {
            m = m / n;
            count++;
        }
        return count;
    }
}