Problem: 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.

Submission attempts (in order):
import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    Aone = A - 1
    lcm = int(C * D / fractions.gcd(C, D))

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / lcm)
    Bdec = Bc + Bd - Blcm

#    print(Bc,Bd,Blcm)

    Ac = int(Aone / C)
    Ad = int(Aone / D)
    Alcm = int(Aone / lcm)
    Adec = Ac + Ad - Alcm

#    print(Ac,Ad,Alcm)

    print(B - A + 1 - (Bdec - Adec))


main()

import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    Aone = A - 1
    lcm = C * D / fractions.gcd(C, D)

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / lcm)
    Bdec = Bc + Bd - Blcm

#    print(Bc,Bd,Blcm)

    Ac = int(Aone / C)
    Ad = int(Aone / D)
    Alcm = int(Aone / lcm)
    Adec = Ac + Ad - Alcm

#    print(Ac,Ad,Alcm)

    print(B - A + 1 - (Bdec - Adec))


main()

import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    Aone = A - 1
    lcm = int(C / fractions.gcd(C, D) * D)

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / lcm)
    Bdec = B - Bc - Bd + Blcm

#    print(Bc,Bd,Blcm)

    Ac = int(Aone / C)
    Ad = int(Aone / D)
    Alcm = int(Aone / lcm)
    Adec = Aone - Ac - Ad + Alcm

#    print(Ac,Ad,Alcm)

    print(Bdec - Adec)


main()

import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    A -= 1
    lcm = C * D / fractions.gcd(C, D)

    Bc = int(B // C)
    Bd = int(B // D)
    Blcm = int(B // lcm)
    Bdec = B - (Bc + Bd - Blcm)

    Ac = int(A // C)
    Ad = int(A // D)
    Alcm = int(A // lcm)
    Adec = A - (Ac + Ad - Alcm)

    print(Bdec - Adec)


main()

import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    lcm = C * D / fractions.gcd(C, D)

    Ac = int(A/C)
    if A % C == 0:
        Ac-=1

    Bc = int(B/C)
    cnum = Bc - Ac

    Ad = int(A/D)
    if A % D == 0:
        Ad-=1

    Bd = int(B/D)
    dnum =Bd - Ad

    Alcm = int(A/lcm)
    if A % lcm == 0:
        Alcm-=1

    Blcm = int(B/lcm)
    lcmnum = Blcm - Alcm

    print(B - A + 1 - (cnum + dnum - lcmnum))

main()

import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    Aone = A - 1
    lcm = int(C / fractions.gcd(C, D) * D)

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / lcm)
    Bdec = Bc + Bd - Blcm

#    print(Bc,Bd,Blcm)

    Ac = int(Aone / C)
    Ad = int(Aone / D)
    Alcm = int(Aone / lcm)
    Adec = Ac + Ad - Alcm

#    print(Ac,Ad,Alcm)

    print(B - A + 1 - (Bdec - Adec))


main()

import sys
 
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a
 
 
 
def lcm(a, b):
    return a * b // (gcd(a, b))
 
 
 
def main():
    A, B, C, D = map(int, input().split())
    Aone = A - 1
    CDlcm = lcm(C, D)
 
    Bc = B // C
    Bd = B // D
    Blcm = B // CDlcm
    Bdec = B - Bc - Bd + Blcm
 
#    print(Bc,Bd,Blcm)
 
    Ac = Aone // C
    Ad = Aone // D
    Alcm = Aone // CDlcm
    Adec = Aone - Ac - Ad + Alcm
 
#    print(Ac,Ad,Alcm)
 
    print(Bdec - Adec)
 

import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    A -= 1
    lcm = C * D / fractions.gcd(C, D)

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / lcm)
    Bdec = B - (Bc + Bd - Blcm)

    Ac = int(A / C)
    Ad = int(A / D)
    Alcm = int(A / lcm)
    Adec = A - (Ac + Ad - Alcm)

    print(Bdec - Adec)


main()

import sys
 
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a
 
 
 
def lcm(a, b):
    return a * b // (gcd(a, b))
 
 
 
def main():
    A, B, C, D = map(int, input().split())
    Aone = A - 1
    CDlcm = lcm(C, D)
 
    Bc = B // C
    Bd = B // D
    Blcm = B // CDlcm
    Bdec = B - Bc - Bd + Blcm
 
#    print(Bc,Bd,Blcm)
 
    Ac = Aone // C
    Ad = Aone // D
    Alcm = Aone // CDlcm
    Adec = Aone - Ac - Ad + Alcm
 
#    print(Ac,Ad,Alcm)
 
    print(Bdec - Adec)
 
 
main()

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted