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):
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
a,b,c,d = map(int,input().split())
m = int(c*d/gcd(c,d))
if a%c < b%c:
  xc = (b-a+1)//c
elif a%c > b%c and b%c == 0 and a%c == 1:
  xc = (b-a+1)//c
elif a%c > b%c:
  xc = (b-a+1)//c +1
elif a%c == b%c and a%c == 0:
  xc = (b-a+1)//c +1
else:
  xc  = (b-a+1)//c

if a%d < b%d:
  xd = (b-a+1)//d
elif a%d > b%d and b%d == 0 and a%d == 1:
  xd = (b-a+1)//d
elif a%d > b%d:
  xd = (b-a+1)//d +1
elif a%d == b%d and a%d == 0:
  xd = (b-a+1)//d +1
else:
  xd  = (b-a+1)//d

if a%m < b%m:
  xm = (b-a+1)//m
elif a%m > b%m and b%m == 0 and a%m == 1:
  xm = (b-a+1)//m
elif a%m > b%m:
  xm = (b-a+1)//m +1
elif a%m == b%m and a%m == 0:
  xm = (b-a+1)//m +1
else:
  xm  = (b-a+1)//m

print(b-a+1-xc-xd+xm)

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
a,b,c,d = map(int,input().split())
m = int(c*d/gcd(c,d))
if a%c < b%c:
  xc = (b-a+1)//c
elif a%c > b%c and b%c == 0:
  xc = (b-a+1)//c
elif a%c > b%c:
  xc = (b-a+1)//c +1
elif a%c == b%c and a%c == 0:
  xc = (b-a+1)//c +1
else:
  xc  = (b-a+1)//c

if a%d < b%d:
  xd = (b-a+1)//d
elif a%d > b%d and b%d == 0:
  xd = (b-a+1)//d
elif a%d > b%d:
  xd = (b-a+1)//d +1
elif a%d == b%d and a%d == 0:
  xd = (b-a+1)//d +1
else:
  xd  = (b-a+1)//d

if a%m < b%m:
  xm = (b-a+1)//m
elif a%m > b%m and b%m == 0:
  xm = (b-a+1)//m
elif a%m > b%m:
  xm = (b-a+1)//m +1
elif a%m == b%m and a%m == 0:
  xm = (b-a+1)//m +1
else:
  xm  = (b-a+1)//m

print(b-a+1-xc-xd+xm)

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
a,b,c,d = map(int,input().split())
m = int(c*d/gcd(c,d))
if c == 1 or d == 1:
  print(0)
  exit()
if a%c < b%c and a%c == 0 and b%c != c-1:
  xc = (b-a+1)//c + 1
elif a%c < b%c:
  xc = (b-a+1)//c
elif a%c > b%c and b%c == 0 and a%c == 1:
  xc = (b-a+1)//c
elif a%c > b%c:
  xc = (b-a+1)//c +1
elif a%c == b%c and a%c == 0:
  xc = (b-a+1)//c +1
else:
  xc  = (b-a+1)//c

if a%d < b%d and a%d == 0 and b%d != d-1:
  xd = (b-a+1)//d +1
elif a%d < b%d:
  xd = (b-a+1)//d
elif a%d > b%d and b%d == 0 and a%d == 1:
  xd = (b-a+1)//d
elif a%d > b%d:
  xd = (b-a+1)//d +1
elif a%d == b%d and a%d == 0:
  xd = (b-a+1)//d +1
else:
  xd  = (b-a+1)//d

if a%m < b%m and a%m == 0 and b%m != m-1:
  xm = (b-a+1)//m +1
elif a%m < b%m:
  xm = (b-a+1)//m
elif a%m > b%m and b%m == 0 and a%m == 1:
  xm = (b-a+1)//m
elif a%m > b%m:
  xm = (b-a+1)//m +1
elif a%m == b%m and a%m == 0:
  xm = (b-a+1)//m +1
else:
  xm  = (b-a+1)//m

print(b-a+1-xc-xd+xm)

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
a,b,c,d = map(int,input().split())
m = int(c*d/gcd(c,d))
if a%c < b%c:
  xc = (b-a+1)//c
elif a%c > b%c and b%c == 0:
  xc = (b-a+1)//c
elif a%c > b%c:
  xc = (b-a+1)//c +1
elif a%c == b%c and a%c == 0:
  xc = (b-a+1)//c +1
else:
  xc  = (b-a+1)//c

if a%d < b%d:
  xd = (b-a+1)//d
elif a%d > b%d and b%d == 0:
  xd = (b-a+1)//d
elif a%d > b%d:
  xd = (b-a+1)//d +1
elif a%d == b%d and a%d == 0:
  xd = (b-a+1)//d +1
else:
  xd  = (b-a+1)//d

if a%m < b%m:
  xm = (b-a+1)//m
elif a%m > b%m and b%m == 0:
  xm = (b-a+1)//m
elif a%m > b%m:
  xm = (b-a+1)//m +1
elif a%m == b%m and a%m == 0:
  xm = (b-a+1)//m +1
else:
  xm  = (b-a+1)//m

print("{} {} {}".format(xc,xd,xm))
print(b-a+1-xc-xd+xm)

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
a,b,c,d = map(int,input().split())
m = int(c*d/gcd(c,d))
if a%c < b%c:
  xc = (b-a+1)//c
elif a%c > b%c and b%c == 0 and a%c == 1:
  xc = (b-a+1)//c
elif a%c > b%c:
  xc = (b-a+1)//c +1
elif a%c == b%c and a%c == 0:
  xc = (b-a+1)//c +1
else:
  xc  = (b-a+1)//c

if a%d < b%d:
  xd = (b-a+1)//d
elif a%d > b%d and b%d == 0 and a%d == 1:
  xd = (b-a+1)//d
elif a%d > b%d:
  xd = (b-a+1)//d +1
elif a%d == b%d and a%d == 0:
  xd = (b-a+1)//d +1
else:
  xd  = (b-a+1)//d

if a%m < b%m:
  xm = (b-a+1)//m
elif a%m > b%m and b%m == 0 and a%m == 1:
  xm = (b-a+1)//m
elif a%m > b%m:
  xm = (b-a+1)//m +1
elif a%m == b%m and a%m == 0:
  xm = (b-a+1)//m +1
else:
  xm  = (b-a+1)//m

print(b-a+1-xc-xd+xm)

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
a,b,c,d = map(int,input().split())
m = int(c*d/gcd(c,d))
if c == 1 or d == 1:
  print(0)
  exit()
if a%c < b%c:
  xc = (b-a+1)//c
elif a%c > b%c and b%c == 0 and a%c == 1:
  xc = (b-a+1)//c
elif a%c > b%c:
  xc = (b-a+1)//c +1
elif a%c == b%c and a%c == 0:
  xc = (b-a+1)//c +1
else:
  xc  = (b-a+1)//c

if a%d < b%d:
  xd = (b-a+1)//d
elif a%d > b%d and b%d == 0 and a%d == 1:
  xd = (b-a+1)//d
elif a%d > b%d:
  xd = (b-a+1)//d +1
elif a%d == b%d and a%d == 0:
  xd = (b-a+1)//d +1
else:
  xd  = (b-a+1)//d

if a%m < b%m:
  xm = (b-a+1)//m
elif a%m > b%m and b%m == 0 and a%m == 1:
  xm = (b-a+1)//m
elif a%m > b%m:
  xm = (b-a+1)//m +1
elif a%m == b%m and a%m == 0:
  xm = (b-a+1)//m +1
else:
  xm  = (b-a+1)//m

print(b-a+1-xc-xd+xm)

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

a,b,c,d = map(int,input().split())

m = int(c*d/gcd(c,d))
xc = b//c - (a-1)//c
xd = b//d - (a-1)//d
xm = b//m - (a-1)//m
print(b-a+1-xc-xd+xm)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted