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 C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "Input1";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("4 9 2 3");
            //2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("10 40 6 8");
            //23
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("314159265358979323 846264338327950288 419716939 937510582");
            //532105071133627368
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        long[] wkArr = InputList[0].Split(' ').Select(X => long.Parse(X)).ToArray();

        long A = wkArr[0];
        long B = wkArr[1];
        long C = wkArr[2];
        long D = wkArr[3];
        long LCM = C * D / DeriveGCD(C, D);

        //A以上B以下のCの倍数
        long Cnt1 = DeriveBaisuuCnt(A, B, C);
        //A以上B以下のDの倍数
        long Cnt2 = DeriveBaisuuCnt(A, B, D);
        //A以上B以下のCとDの公倍数
        long Cnt3 = DeriveBaisuuCnt(A, B, LCM);

        Console.WriteLine(Cnt1 + Cnt2 - Cnt3);
    }

    //p1以上p2以下のp3の倍数の数を返す
    static long DeriveBaisuuCnt(long p1, long p2, long p3)
    {
        long N1;
        if (p1 % p3 == 0) {
            N1 = p1 / p3;
        }
        else {
            N1 = p1 / p3 + 1;
        }

        long N2 = p2 / p3;

        return N2 - N1 + 1;
    }

    //ユークリッドの互除法で2数の最大公約数を求める
    static long DeriveGCD(long pVal1, long pVal2)
    {
        long WarareruKazu = pVal2;
        long WaruKazu = pVal1;

        while (true) {
            long Amari = WarareruKazu % WaruKazu;
            if (Amari == 0) return WaruKazu;
            WarareruKazu = WaruKazu;
            WaruKazu = Amari;
        }
    }
}