Problem:
Score : 300 points

Problem Statement

You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Constraints

1\leq A\leq B\leq 10^{18}

1\leq C,D\leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Sample Input 1

4 9 2 3

Sample Output 1

2

5 and 7 satisfy the condition.

Sample Input 2

10 40 6 8

Sample Output 2

23

Sample Input 3

314159265358979323 846264338327950288 419716939 937510582

Sample Output 3

532105071133627368

Solution in Go (1.6) (judge verdict: Wrong Answer)

package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	list := getStdinIntArr64()
	var A int64 = list[0]
	var B int64 = list[1]
	var C int64 = list[2]
	var D int64 = list[3]

	var cnt int64 = B - A + 1

	if A%C == 0 {
		cnt -= (B-A)/C + 1
		fmt.Printf("cnt1 = %d\n", (B-A)/C+1)
	} else {
		cnt -= (B - A) / C
		fmt.Printf("cnt2 = %d\n", (B-A)/C)
	}

	if A%D == 0 {
		cnt -= (B-A)/D + 1
		fmt.Printf("cnt1 = %d\n", (B-A)/D+1)
	} else {
		cnt -= (B - A) / D
		fmt.Printf("cnt2 = %d\n", (B-A)/D)
	}

	/*
		l := lcm(C, D)
		if A%l == 0 {
			cnt += (B-A)/l + 1
			fmt.Printf("lcm = %d\n", l)
			fmt.Printf("cnt1 = %d\n", (B-A)/l+1)
		} else {
			cnt += (B - A) / l
			fmt.Printf("lcm = %d\n", l)
			fmt.Printf("cnt2 = %d\n", (B-A)/l)
		}
	*/

	fmt.Printf("%d\n", cnt)
}

func gcd(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}
func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}