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 Go (1.6) (judge verdict: Time Limit Exceeded)

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	In := readLineInt()
	A, B := In[0], In[1]
	AMap, BMap := map[int]int{}, map[int]int{}
	End := max(A, B)
	for prime := 2; prime <= End; prime++ {
		isPrime := true
		for p := 2; p < prime; p++ {
			if (prime % p) == 0 {
				isPrime = false
				break
			}
		}

		if isPrime {
			p, c := multiplier(A, prime)
			if c != -1 {
				A /= p
				AMap[prime] = c
			}

			p, c = multiplier(B, prime)
			if c != -1 {
				B /= p
				BMap[prime] = c
			}
		}

		if A == 1 && B == 1 {
			break
		}
	}

	Max := AMap
	for k, v := range BMap {
		mv := Max[k]
		Max[k] = max(mv, v)
	}

	result := 1
	for k, v := range Max {
		result *= pow(k, v)
	}
	fmt.Println(result)
}

func multiplier(value int, prime int) (int, int) {
	now, previous, count := 1, 0, 1
	for {
		now = now * prime
		if value%now != 0 {
			if previous != 0 {
				value = value / previous
				return previous, count - 1
			}
			break
		} else {
			previous = now
		}
		count++
	}
	return -1, -1
}

/////////////////////////////////////////
func readLineInt() []int {
	result := make([]int, 0)
	for _, v := range strings.Split(readLine(), " ") {
		i, _ := strconv.Atoi(v)
		result = append(result, i)
	}
	return result
}

var reader = bufio.NewReaderSize(os.Stdin, 1e6)

func readLine() string {
	result := make([]byte, 0, 1e6)
	for {
		line, remains, e := reader.ReadLine()
		if e != nil {
			panic(e)
		}
		result = append(result, line...)
		if !remains {
			break
		}
	}
	return string(result)
}

func Loop(start, end int, f func(i int)) {
	for i := start; i < end; i++ {
		f(i)
	}
}

func pow(a, b int) int {
	result := a
	Loop(0, b-1, func(i int) {
		result = result * a
	})

	return result
}

func max(a ...int) int {
	result := 0

	for _, i := range a {
		if result < i {
			result = i
		}
	}

	return result
}