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



Sample input:
4 9 2 3


Sample output:
2

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
if c>b and d>b:
  print(b-a+1)
  exit()
elif c>b:
  for i in range(b):
    if d*i>=a:
      d1=i*d
  print(b-a-(b-d1)//d)
  exit()
elif d>b:
  for i in range(b):
    if c*i>=a:
      c1=i*c
  print(b-a-(b-c1)//c)
  exit()
else :
  c1=a//c+1
  d1=a//d+1
  clst=[c*i for i in range(c1,(b-c*c1)//c+c1+1)]    
  dlst=[d*i for i in range(d1,(b-d*d1)//d+c1+1)]
  lst=set(clst+dlst)
  print(b-a+1-len(lst))

Submission status: Wrong Answer

Solution code:
import math
import fractions
a, b, c, d = (int(i) for i in input().split())

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y) 

def num_div(first, last, div):
  return last//div - first//div

c_div = num_div(a, b, c)
d_div = num_div(a, b, d)
cd_div = num_div(a, b, lcm(c, d))

print(b - a - (c_div + d_div - cd_div) + 1)

Submission status: Wrong Answer

Solution code:
import math
import fractions
a, b, c, d = (int(i) for i in input().split())

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
diff = (b - a)
c_div = math.ceil(diff/c) if (diff/c >= 1) else 0 
d_div = math.ceil(diff/d) if (diff/d >= 1) else 0
cd_div = math.ceil(diff/lcm(c, d)) if (diff/lcm(c, d) >= 1) else 0 

if max(a, b) < min(c, d) and b // c - a // c != 2:
  c_div -= 1
  
if max(a, b) < min(c, d) and b // d - a // d != 2:
  d_div -= 1
  

if 1 in [c, d]:
  print(0)
else:
  print(b - a - (c_div + d_div - cd_div) + 1)

Submission status: Wrong Answer

Solution code:
import math
import fractions
a, b, c, d = (int(i) for i in input().split())

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
diff = (b - a)
c_div = math.ceil(diff/c) if (diff/c >= 1) else 0 
d_div = math.ceil(diff/d) if (diff/d >= 1) else 0
cd_div = math.ceil(diff/lcm(c, d)) if (diff/lcm(c, d) >= 1) else 0 

if 1 in [c, d]:
  print(0)
else:
  print(b - a - (c_div + d_div - cd_div) + 1)

Submission status: Wrong Answer

Solution code:
import math
import fractions
a, b, c, d = (int(i) for i in input().split())

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
diff = (b - a)
c_div = math.ceil(diff/c) if (diff/c >= 1) else 0 
d_div = math.ceil(diff/d) if (diff/d >= 1) else 0
cd_div = math.ceil(diff/lcm(c, d)) if (diff/lcm(c, d) >= 1) else 0 

print(b - a - (c_div + d_div - cd_div) + 1)

Submission status: Wrong Answer

Solution code:
import math
a, b, c, d = (int(i) for i in input().split())

diff = (b - a)
c_div = math.ceil(diff/c)
d_div = math.ceil(diff/d)
cd_div = math.ceil(diff/(c * d))

print(b - a - (c_div + d_div - cd_div) + 1)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

a, b, c, d = map(int, input().split())
cnt = (b // c + b // d - b // lcm(a, b)) - ((a - 1) // c + (a - 1) // d)
print((b - a + 1) - cnt)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
cnt = (b // c + b // d) - (a // c + a // d)
print((b - a) - cnt)

Submission status: Wrong Answer

Solution code:
a,b,c,d= map(int,input().split())
k=b-a+1
n1=b//c
n2=a//c
m1=b//d
m2=a//d
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def lcm(a,b):
     return a*b//gcd(a,b)
l1=b//(lcm(c,d))
l2=a//(lcm(c,d))
n=n1-n2
m=m1-m2
l=l1-l2
print(k+l-n-m)

Submission status: Wrong Answer

Solution code:
import fractions as f
a,b,c,d=map(int,input().split())
cnt=0
if c%a==0 or c%b==0:
    if d%a==0 or d%b==0:
        cnt=1
e=a//c
e1=a//d
e2=a//(c*d//f.gcd(c,d))
ff=b//c
ff1=b//d
ff2=b//(c*d//f.gcd(c,d))
if cnt==1:
    print(b-ff-ff1+ff2-a+e+e1-e2)
else:
    print(b-ff-ff1+ff2-a+e+e1-e2+1)

Submission status: Wrong Answer

Solution code:
import math
import fractions
(a,b,c,d)=map(int,input().split())
g=int(c*d/fractions.gcd(c,d))
k=0
k+=int(b/c)+int(b/d)-int(b/g)-int((a-1)/c)-int((a-1)/d)+int((a-1)/g)

print(b-a+1-k)

Submission status: Wrong Answer

Solution code:
import fractions

A, B, C, D = map(int, input().split())
lcm = A *B // fractions.gcd(A, B)
a = (A // C) + (A // D) - (A//lcm)
b = (B // C) + (B // D) - (B//lcm)
ab = b- a
print(B-A-ab)

Submission status: Wrong Answer

Solution code:
import fractions as f
a,b,c,d=map(int,input().split())
if b-a>c*d//(f.gcd(c,d)):
    print(b-b//c-b//d+b//(c*d//(f.gcd(c,d)))-a+a//c+a//d-a//(c*d//f.gcd(c,d))+1)
else:
    print(b-b//c-b//d+b//(c*d//(f.gcd(c,d)))-a+a//c+a//d-a//(c*d//f.gcd(c,d)))

Submission status: Wrong Answer

Solution code:
import fractions as f
a,b,c,d=map(int,input().split())
if b-a+1>c*d//(f.gcd(c,d)):
    print(b-b//c-b//d+b//(c*d//(f.gcd(c,d)))-a+a//c+a//d-a//(c*d//f.gcd(c,d))+1)
else:
    print(b-b//c-b//d+b//(c*d//(f.gcd(c,d)))-a+a//c+a//d-a//(c*d//f.gcd(c,d)))

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
if (b-a)%2==1:
    print(b-a-(b-a)//c-(b-a)//d)
else:
    print(b-a-(b-a)//c-(b-a)//d+1)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
t = b - a + 1

e = (b//c - a//c)
if a % c ==0:
  e += 1
f = (b//d - a//d)
if a % d ==0:
  f += 1
g = b//(c*d) - a//(c*d)
if a % (c*d) == 0:
  g += 1
print(t - (e+f-g))

Submission status: Wrong Answer

Solution code:
import fractions

def lcm(x,y):
    return (x * y) // fractions.gcd(x,y)

A,B,C,D = [int(i) for i in input().split(" ")]

AB = B
BC = B//C
BD = B//D
CD = lcm(C,D)
BCD = B//CD
unionB = BC+BD-BCD
AA = A-1
AC = AA//C
AD = AA//D
ACD = AA//CD
unionA = AC+AD-ACD 
print(unionB - unionA)

Submission status: Wrong Answer

Solution code:
import fractions

def lcm(x,y):
    return (x * y) // fractions.gcd(x,y)

A,B,C,D = [int(i) for i in input().split(" ")]
AB = B
BC = B//C
BD = B//D
CD = lcm(C,D)
BCD = B//CD
unionB = BC+BD-BCD
AA = A-1
AC = AA//C
AD = AA//D
ACD = AA//CD
unionA = AC+AD-ACD 
print(B - unionB - unionA)

Submission status: Wrong Answer

Solution code:
import fractions

def lcm(x,y):
    return (x * y) // fractions.gcd(x,y)

A,B,C,D = [int(i) for i in input().split(" ")]
AB = B-A
BC = AB//C
BD = AB//D
CD = lcm(C,D)
BCD = AB//CD
union = BC+BD-BCD
print(AB - union)

Submission status: Wrong Answer

Solution code:
import math 

A,B,C,D = [int(i) for i in input().split(" ")]
AB = B-A+1
BC = round(AB/C)
BD = round(AB/D)
CD = C*D
BCD = round(AB/CD)
union = BC+BD-BCD
print(AB - union)

Submission status: Wrong Answer

Solution code:
import math 

A,B,C,D = [int(i) for i in input().split(" ")]
AB = B-A
BC = math.ceil(AB/C)
BD = math.ceil(AB/D)
CD = C*D
BCD = math.ceil(AB/CD)
union = BC+BD-BCD
print(AB - union+1)

Submission status: Wrong Answer

Solution code:
a, b, c, d=(int(x) for x in input().split())
cnt=0
for i in range(a,b+1):
  if i%c!=0 and i%d!=0:
    cnt+=1
  if i%c==0:
    k=(b-i)/c
    cnt+=(k*(c-1))
    l=b-i-c*k
    cnt+=l
    break
    
    

print(cnt)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

A, B, C, D = map(int,input().split())

cd_lcm = C * D//gcd(C, D)

def cnt_mod0(st, ed, x):
    c = 0
    if st % x !=0: st += st % x
    if st > ed:return 0
    c = (ed-st) // x + 1
    return c

cnt = B- A + 1 - (cnt_mod0(A, B, C) + cnt_mod0(A, B, D) - cnt_mod0(A, B, cd_lcm))
print(cnt)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

A, B, C, D = map(int,input().split())

cd_lcm = C * D//gcd(C, D)

def cnt_mod0(st, ed, x):
    c = 0
    if st % x !=0: st += st % x
    c = (ed-st) // x + 1
    return c

cnt = B- A + 1 - (cnt_mod0(A, B, C) + cnt_mod0(A, B, D) - cnt_mod0(A, B, cd_lcm))
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
import fractions
A,B,C,D = map(int,input().split())
def lcm(x,y):
    return(x*y)//fractions.gcd(x,y)
BC = math.floor(B/C)
BD = math.floor(B/D)
BCD = math.floor(B/lcm(C,D))
A1C = math.floor((A-1)/C)
A1D = math.floor((A-1)/D)
A1CD = math.floor((A-1)/lcm(C,D))
print((B-BC-BD+BCD)-((A-1)-A1C-A1D+A1CD))

Submission status: Wrong Answer

Solution code:
import math
import fractions
A,B,C,D = map(int,input().split())
countC = math.floor(B/C) - (math.ceil(A/C)-1)
countD = math.floor(B/D) - (math.ceil(A/D)-1)
def lcm(x,y):
    return(x*y)//fractions.gcd(x,y)
lcmCD = lcm(C,D)
countlcm = math.floor(B/lcmCD) - (math.ceil(A/lcm(C,D))-1)
print(B - A + 1 - (countC + countD - countlcm))

Submission status: Wrong Answer

Solution code:
import math
import fractions
A,B,C,D = map(int,input().split())
if C == 1 or D == 1:
    print(0)
else:
    countC = math.floor(B/C) - math.floor((A-1)/C)
    countD = math.floor(B/D) - math.floor((A-1)/D)
    def lcm(x,y):
        return(x*y)//fractions.gcd(x,y)
    lcmCD = lcm(C,D)
    countlcm = math.floor(B/lcmCD) - math.floor((A-1)/lcm(C,D))
    print(B - A + 1 - (countC + countD - countlcm))

Submission status: Wrong Answer

Solution code:
import math
import fractions
A,B,C,D = map(int,input().split())
countC = math.floor(B/C) - math.floor((A-1)/C)
countD = math.floor(B/D) - math.floor((A-1)/D)
def lcm(x,y):
    return(x*y)//fractions.gcd(x,y)
lcmCD = lcm(C,D)
countlcm = math.floor(B/lcmCD) - math.floor((A-1)/lcm(C,D))
print(B - A + 1 - (countC + countD - countlcm))

Submission status: Wrong Answer

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

round = lambda x:int((x*2+1)//2)
diff = b-a+1
print(diff - round(diff/c) - round(diff/d) + round(diff/(c*d)))

Submission status: Wrong Answer

Solution code:
import fractions

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

# 最小公倍数を求める
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def cal(num, a, b):
    x = num // a
    y = num // b
    z = num // (lcm(a, b))
    print('z={}'.format(z))
    return num - (x + y - z)

num_a = cal(b, c, d)
num_b = cal(a-1, c, d)

print(num_a - num_b)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

a, b, c, d = map(int, input().split())
lcm = c * d / gcd(c, d)


def nd(n, c, d):
    return n - n // c - n // d + n // lcm


ans = nd(b, c, d) - nd(a-1, c, d)
print(int(ans))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

a, b, c, d = map(int, input().split())
lcm = c / gcd(c, d) * d


def nd(n, c, d):
    return n - n // c - n // d + n // lcm


ans = nd(b, c, d) - nd(a-1, c, d)
print(int(ans))

Submission status: Wrong Answer

Solution code:
from fractions import gcd


def num(n, c, d, lcm):
    return n - n // c - n // d + n // lcm


a, b, c, d = map(int, input().split())
lcm = c / gcd(c, d) * d

ans = num(b, c, d, lcm) - num(a-1, c, d, lcm)
print(int(ans))

Submission status: Wrong Answer

Solution code:
from fractions import gcd


def num(n, c, d, lcm):
    return n - n // c - n // d + n // lcm


a, b, c, d = map(int, input().split())
lcm = c / gcd(c, d) * d

ans = num(b, c, d, lcm) - num(a-1, b, d, lcm)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
# 方針はb以下の条件にあったものからa - 1以下の条件にあったものを引く
# 最小公倍数を使って引きすぎたものを置換

# greatest common divisor
# gcd はユークリッドの互除法をつかって再帰の形で求められる
def gcd(x,y):
  if y == 0: return x
  return gcd(y,x%y)

# least common multiple
# // を使った除算で小数点を省ける
def lcm(e,f):
  return e * f // gcd(e,f)
a,b,c,d = map(int,input().split())

if a==b:
  print(str(0))
  sys.exit()
all = b - (b // c) - (b // d) + (b // lcm(c,d))
to_a = (a - 1) - ((a - 1) // c) - ((a - 1) // d) + (a // lcm(c,d))
print(str(all - to_a))

Submission status: Wrong Answer

Solution code:
# 方針はb以下の条件にあったものからa - 1以下の条件にあったものを引く
# 最小公倍数を使って引きすぎたものを置換

# greatest common divisor
# gcd はユークリッドの互除法をつかって再帰の形で求められる
def gcd(x,y):
  if y == 0: return x
  return gcd(y,x%y)

# least common multiple
# // を使った除算で小数点を省ける
def lcm(e,f):
  return e * f // gcd(e,f)
a,b,c,d = map(int,input().split())

all = b - (b // c) - (b // d) + (b // lcm(c,d))
to_a = (a - 1) - ((a - 1) // c) - ((a - 1) // d) + (a // lcm(c,d))
print(str(all - to_a))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
#from math import gcd
A, B, C, D = map(int, input().split())
lcm = C * D / gcd(C, D)
E = A - 1
print(int(B - E - (B // C + B // D - B // lcm - E // C - E // D + E // lcm)))

Submission status: Wrong Answer

Solution code:
# 2019-11-14 20:54:46(JST)
import sys
# import collections
import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 


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

def lcm(a, b):
    return a * b // gcd(a, b)

def main():
    a, b, c, d = [int(x) for x in sys.stdin.readline().split()]
    divisors = 0
    divisors += b // c - math.ceil(a / c) + 1
    divisors += b // d - math.ceil(a / d) + 1
    cd = lcm(c, d)
    divisors -= b // cd - math.ceil(a / cd) + 1
    ans = b - a + 1 - divisors
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from decimal import *
import fractions
import sys

num = list(map(int, input().split()))

A = num[0]
B = num[1]
C = num[2]
D = num[3]

def ans_mthd(i, j, k):
    return Decimal((i - i // j - i // k + i * fractions.gcd(j, k) / j // k ))

ans = ans_mthd(B, C, D)-ans_mthd(A-1, C, D)
# print(math.gcd(C, D))
# print(C * D)
# print(ans_mthd(B, C, D) // 1)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
CD=fractions.gcd(c,d)
cd=(c*d)//CD
width=b-a
cnt=0
if width%c==0:
  if a%c==0:
    cnt+=(width//c)+1
  else:
    cnt+=(width//c)
else:
  if c-(a%c)+b%c>=c:
    cnt+=(width//c)
  else:
    cnt+=(width//c)+1

if width%d==0:
  if a%d==0:
    cnt+=(width//d)+1
  else:
    cnt+=(width//d)
else:
  if d-(a%d)+b%d>=d:
    cnt+=(width//d)
  else:
    cnt+=(width//d)+1

if width%cd==0:
  if a%cd==0:
    cnt-=(width//cd)+1
  else:
    cnt-=(width//cd)
else:
  if cd-(a%cd)+b%cd>=cd:
    cnt-=(width//cd)
  else:
    cnt-=(width//cd)+1

print(b-a+1-cnt)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a, b, c, d = map(int, input().split())

def lcm(x, y):
    return x*y/gcd(x,y)

def notDiv(a, c, d):
    return a - int(a/c) - int(a/d) + int(a/lcm(c, d))

print( notDiv(b, c, d)-notDiv(a-1, c, d) )

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
CD=fractions.gcd(c,d)
cd=(c*d)//CD
width=b-a
cnt=0
if width%c==0:
  if a%c==0:
    cnt+=(width//c)+1
  else:
    cnt+=(width//c)
else:
  if a-(a%c)+b%c>=c:
    cnt+=(width//c)
  else:
    cnt+=(width//c)+1

if width%d==0:
  if a%d==0:
    cnt+=(width//d)+1
  else:
    cnt+=(width//d)
else:
  if a-(a%d)+b%d>=d:
    cnt+=(width//d)
  else:
    cnt+=(width//d)+1

if width%cd==0:
  if a%cd==0:
    cnt-=(width//cd)+1
  else:
    cnt-=(width//cd)
else:
  if a-(a%cd)+b%cd>=cd:
    cnt-=(width//cd)
  else:
    cnt-=(width//cd)+1

print(b-a+1-cnt)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
CD=fractions.gcd(c,d)
cd=(c*d)//CD
width=b-a
cnt=0
if width%c==0:
  if a%c==0:
    cnt+=(width//c)+1
  else:
    cnt+=(width//c)+1
else:
  cnt+=(width//c)+1

if width%d==0:
  if a%d==0:
    cnt+=(width//d)+1
  else:
    cnt+=(width//d)+1
else:
  cnt+=(width//d)+1

if width%cd==0:
  if a%cd==0:
    cnt-=(width//cd)+1
  else:
    cnt-=(width//cd)+1
else:
  cnt-=(width//cd)+1

print(b-a+1-cnt)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
CD=fractions.gcd(c,d)
cd=(c*d)//CD
width=b-a
cnt=0
if width%c==0:
  if a%c==0:
    cnt+=(width//c)+1
  else:
    cnt+=(width//c)
else:
  cnt+=(width//c)+1

if width%d==0:
  if a%d==0:
    cnt+=(width//d)+1
  else:
    cnt+=(width//d)
else:
  cnt+=(width//d)+1

if width%cd==0:
  if a%cd==0:
    cnt-=(width//cd)+1
  else:
    cnt-=(width//cd)
else:
  cnt-=(width//cd)+1

print(b-a+1-cnt)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
CD=fractions.gcd(c,d)
cd=(c*d)//CD
width=b-a
cnt=0
if width%c==0:
  if a%c==0:
    cnt+=(width//c)+1
  else:
    cnt+=(width//c)
else:
  cnt+=(width//c)+1

if width%d==0:
  if a%d==0:
    cnt+=(width//d)+1
  else:
    cnt+=(width//d)
else:
  cnt+=(width//d)+1

if width%cd==0:
  if a%cd==0:
    cnt-=(width//cd)+1
  else:
    cnt-=(width//cd)
else:
  cnt-=(width//cd)+1

Submission status: Wrong Answer

Solution code:
import math
import fractions
A,B,C,D = map(int,input().split())
A=A-1

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A_C= math.floor(A/C)
B_C= math.floor(B/C)
A_D= math.floor(A/D)
B_D= math.floor(B/D)
A_CD = math.floor(A/lcm(C,D))
B_CD = math.floor(B/lcm(C,D))

S = B_C - A_C
T = B_D - A_D
U = B_CD - A_CD

ans = (B-A)-(S+T-U)

#print(A_C,B_C,A_D,B_D,A_CD,B_CD)
#print(S,T,U)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import fractions
A,B,C,D = map(int,input().split())

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A_C= math.floor(A/C)
B_C= math.floor(B/C)
A_D= math.floor(A/D)
B_D= math.floor(B/D)
A_CD = math.floor(A/lcm(C,D))
B_CD = math.floor(B/lcm(C,D))

S = B_C - A_C
T = B_D - A_D
U = B_CD - A_CD

ans = (B-A+1)-(S+T-U)

#print(A_C,B_C,A_D,B_D,A_CD,B_CD)
#print(S,T,U)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import fractions
A,B,C,D = map(int,input().split())

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A_C= math.ceil(A/C)
B_C= math.floor(B/C)
A_D= math.ceil(A/D)
B_D= math.floor(B/D)
A_CD = math.ceil(A/lcm(C,D))
B_CD = math.floor(B/lcm(C,D))

S = B_C - A_C + 1
T = B_D - A_D + 1
U = B_CD - A_CD + 1

ans = (B-A+1)-(S+T-U)

#print(S,T,U)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
ABCD = list(map(int,input().split()))
anti = 0

for i in range(ABCD[0],ABCD[1],1):
    if i % ABCD[2] == 0 or i % ABCD[3] == 0:
        anti += 1

ans = ABCD[1] - ABCD[0] - anti
print(ans)

Submission status: Wrong Answer

Solution code:
# coding=utf-8

#N = int(input())
A,B,C,D = map(int, input().split())

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

def lcm(a, b):
    return a * b // gcd (a, b)

all=B-A+1
ac=int((A-1)/C)
bc=int(B/C)
ad=int((A-1)/D)
bd=int(B/D)
alcm=int((A-1)/lcm(C,D))
blcm=int(B/lcm(C,D))

ans=all-(bc-ac-(blcm-alcm)+bd-ad)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding=utf-8

#N = int(input())
A,B,C,D = map(int, input().split())

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

def lcm(a, b):
    return a * b // gcd (a, b)

all=B-A+1
ac=int(A/C)
bc=int(B/C)
ad=int(A/D)
bd=int(B/D)
alcm=int(A/lcm(C,D))
blcm=int(B/lcm(C,D))

ans=all-(bc-ac-(blcm-alcm)+bd-ad)
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
h=0
for i in range(a,b+1):
  if i%c==0 and i%d==0:
    h+=1
    
print(h)

Submission status: Wrong Answer

Solution code:
import fractions
A, B, C, D = map(int, input().split())
def F(x):
    l = x//C
    l += x//D
    l -= C*D//fractions.gcd(C,D)
    return l
print(F(B)-F(A-1))

Submission status: Wrong Answer

Solution code:
import fractions
A, B, C, D = map(int, input().split())

l = int((B-A)/C)
m = int((B-A)/D)
lcm = C*D/fractions.gcd(C,D)
c = B-A-l-m+int((B-A)/lcm)
print(c)

Submission status: Wrong Answer

Solution code:
import fractions

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

cxd = (c * d) // fractions.gcd(c, d)
sa = b - a
ans = (b - b//c - b//d + b//cxd) - ((a-1) - (a-1)//c - (a-1)//d + (a-1)//cxd)

print(ans+1)

Submission status: Wrong Answer

Solution code:
import fractions

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

cxd = (c * d) // fractions.gcd(c, d)
sa = b - a
ans = (b - b//c - b//d + b//cxd) - (a - a//c - a//d + a//cxd)

print(ans+1)

Submission status: Wrong Answer

Solution code:
import fractions

a, b, c, d = map(int, input().split())
cxd = (c * d) // fractions.gcd(c, d)
sa = b - a

print(sa - ((sa//c + sa//d) - sa//cxd))

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd
a,b,c,d = map(int,input().split())

c_num = (b // c - math.ceil(a / c) + 1)
d_num = (b // d - math.ceil(a / d) + 1)


def lcm(x, y):
    return (x * y) // gcd(x, y)
    
e = lcm(c,d)

e_num = (b // e - math.ceil(a / e) + 1)

print((b-a+1)-(c_num+d_num-e_num))

Submission status: Wrong Answer

Solution code:
import unittest


class TestC(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(4, 9, 2, 3), 2)

    def test_2(self):
        self.assertEqual(think(10, 40, 6, 8), 23)

    def test_3(self):
        self.assertEqual(think(314159265358979323, 846264338327950288, 419716939, 937510582), 532105071133627368)

    def test_4(self):
        self.assertEqual(count_multiple_between(4, 9, 2), 3)

    def test_5(self):
        self.assertEqual(count_multiple_between(4, 9, 3), 2)

    def test_6(self):
        self.assertEqual(count_multiple_between(4, 9, 6), 1)

    def test_7(self):
        self.assertEqual(count_multiple_between(10, 40, 6), 5)

    def test_8(self):
        self.assertEqual(count_multiple_between(10, 40, 8), 4)

    def test_9(self):
        self.assertEqual(count_multiple_between(10, 40, 24), 1)


def solve():
    a, b, c, d = read()
    result = think(a, b, c, d)
    write(result)


def read():
    return read_int(4)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a, b, c, d):
    if c > d:
        return think(a, b, d, c)

    if c == 1:
        return 0

    if d % c == 0:
        num_of_multiple = count_multiple_between(a, b, c)
        return b - a - num_of_multiple

    lcm = least_common_multiple(c, d)

    num_of_multiple_c = count_multiple_between(a, b, c)
    num_of_multiple_d = count_multiple_between(a, b, d)
    num_of_multiple_lcm = count_multiple_between(a, b, lcm)

    return b - a + 1 - (num_of_multiple_c + num_of_multiple_d - num_of_multiple_lcm)


def count_multiple_between(a, b, c):
    minimum_multiple = a if a % c == 0 else a + (c - (a % c))
    maximum_mulptile = b if b % c == 0 else b - (b % c)

    if maximum_mulptile < minimum_multiple:
        return 0

    return (maximum_mulptile - minimum_multiple) // c + 1


def least_common_multiple(a, b):
    return (a * b) // greatest_common_divisor(a, b)


def greatest_common_divisor(a, b):
    if a < b:
        return greatest_common_divisor(b, a)

    if a % b == 0:
        return b
    return greatest_common_divisor(b, a % b)


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Submission status: Wrong Answer

Solution code:
import math
a, b, c, d = list(map(int, input().split()))

cnt_c_under_a = int((a-1)/c)
cnt_d_under_a = int((a-1)/d)
cnt_cd_under_a = int((a-1)/(c*d))

cnt_c_all = int(b/c)
cnt_d_all = int(b/d)
cnt_cd_all = int(b/(c*d))

x = ((cnt_c_all + cnt_d_all) - cnt_cd_all) - ((cnt_c_under_a + cnt_d_under_a) - cnt_cd_under_a)

print((b - a + 1) - x)

Submission status: Wrong Answer

Solution code:
#B

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

def lcm(a, b):
    return (a*b)/gcd(a,b)

def getDivisors(a,b,c):
    if (a%c):
        a = ((a//c)+1) * c
    if (b%c):
        b = ((b//c)-1) * c
    #print(a,b)
    return (b-a)//c +1



a,b,c,d = [int(i) for i in input().split()]

#print(lcm(c,d))

diff = b-a+1
ans = diff - ( getDivisors(a, b, c) + getDivisors(a, b, d) - getDivisors(a, b, lcm(c,d)) )
print(int(ans))

Submission status: Wrong Answer

Solution code:
#B

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

def lcm(a, b):
    return (a*b)/gcd(a,b)

def getDivisors(a,b,c):
    if (a%c):
        a = ((a//c)+1) * c
    if (b%c):
        b = ((b//c)+1) * c
    
    return (b-a)//c +1



a,b,c,d = [int(i) for i in input().split()]

#print(lcm(c,d))

diff = b-a+1
ans = diff - ( getDivisors(a, b, c) + getDivisors(a, b, d) - getDivisors(a, b, lcm(c,d)) )
print(int(ans))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
def f(c):
  if a%c!=0:
    if B>=(c-a%c)+a:
      l=(c-a%c)+a
    else:
      l=B-c
  else:
    l=a
  return(1+(B-l)//c)
  
  

a,B,c,d=map(int,input().split())
print(B-a+1-(f(c)+f(d)-f(c*d//gcd(c,d))))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
def f(c):
  if a%c!=0:
    if B>=(c-a%c)+a:
      l=(c-a%c)+a
    else:
      l=B
  else:
    l=a
  return((B-l)//c)
  
  

a,B,c,d=map(int,input().split())
print(B-a-(f(c)+f(d)-f(c*d//gcd(c,d))))

Submission status: Wrong Answer

Solution code:
# a,b,c,d = map(int,input().split())
# import math
# lcm = c * d // math.gcd(c, d)
#
# def num_of_complements(x,c,d):
#     num = x + x//lcm - x//c - x//d
#     return num
#
# ans = num_of_complements(b,c,d) - num_of_complements(a-1,c,d)
# print(ans)
a,b,c,d = map(int,input().split())

def num_of_complements(x,c,d):
    num = x + x//(c*d) - x//c - x//d
    return num

ans = num_of_complements(b,c,d) - num_of_complements(a-1,c,d)
print(ans)

Submission status: Wrong Answer

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

def num_of_complements(x,c,d):
    num = x + x//(c*d) - x//c - x//d
    return num

ans = num_of_complements(b,c,d) - num_of_complements(a-1,c,d)
print(ans)

Submission status: Wrong Answer

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

def num_of_complements(a,b,c,d):
    num = (b-a+1) + (b-a+1)//(c*d) - (b-a+1)//c - (b-a+1)//d
    return num

ans = num_of_complements(a,b,c,d)
print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
import fractions
lcm = int( C*D / ( fractions.gcd(C,D) ) )

first_c = int( ( A - 1) / C)
first_d = int( ( A - 1) / D)
first_cd = int( ( A - 1) / lcm )
first = ( A - 1 ) - ( first_c + first_d - first_cd )

end_c = int( B / C)
end_d = int( B / D)
end_cd = int( B / lcm )
end_ = B - ( end_c + end_d - end_cd )

print(end_ - first)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

def lcm(x,y):
      return (x*y)//gcd(x,y)

lcmv = lcm(c,d)
bc = b//d
bd = b//d
bl = b//lcmv

ac = (a-1)//c
ad = (a-1)//d
al = (a-1)//lcmv

print(b-a+1-((bc+bd-bl)-(ac+ad-al)))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
mm=(c*d)//fractions.gcd(c,d)

bc=b//d
bd=b//d
bmm=b//mm

ac=(a-1)//c
ad=(a-1)//d
amm=(a-1)//mm

print((b-a+1)-((bc+bd-bmm)-(ac+ad-amm)))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
A, B, C, D = [int(i) for i in input().split()]
 
large = np.max([C, D])
small = np.min([C, D])
#print(large)
#print(small)
#quo = large // small
#rem = large % small
g = large
while small != 0:
    large, small = small, large % small
#    print(large)
#    print(small)
 
g = large
#print(g)
 
l = C * D // g
 
num_B_1 = math.floor(B / C)
num_B_2 = math.floor(B / D)
num_B_3 = math.floor(B / l)
num_B = B - (num_B_1 + num_B_2 - num_B_3)
 
num_A_1 = math.floor((A - 1) / C)
num_A_2 = math.floor((A - 1) / D)
num_A_3 = math.floor((A - 1) / l)
num_A = (A - 1) - (num_A_1 + num_A_2 - num_A_3)
 
print(num_B - num_A)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
A, B, C, D = [int(i) for i in input().split()]

large = np.max([C, D])
small = np.min([C, D])
#print(large)
#print(small)
#quo = large // small
#rem = large % small
g = large
while small != 0:
    large, small = small, large % small
#    print(large)
#    print(small)

g = large
#print(g)

l = C * D // g

num_B_1 = math.floor(B / C)
num_B_2 = math.floor(B / D)
num_B_3 = math.floor(B / l)
#num_B_1 = B // C
#num_B_2 = B // D
#num_B_3 = B // l
num_B = B - (num_B_1 + num_B_2 - num_B_3)

num_A_1 = math.floor((A - 1) / C)
num_A_2 = math.floor((A - 1) / D)
num_A_3 = math.floor((A - 1) / l)
#num_A_1 = (A - 1) // C
#num_A_2 = (A - 1) // D
#num_A_3 = (A - 1) // l
num_A = (A - 1) - (num_A_1 + num_A_2 - num_A_3)

print(num_B - num_A)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
A, B, C, D = [int(i) for i in input().split()]
 
large = np.max([C, D])
small = np.min([C, D])
 
def gcd(a, b):
    while b:
        a, b = b, a % b
    print(a)
    return a
 
def lcm(a, b):
    return a * b // gcd (a, b)
 
num_B_1 = B // C
num_B_2 = B // D
num_B_3 = B // lcm(large, small)
 
num_A_1 = (A-1) // C
num_A_2 = (A-1) // D
num_A_3 = (A-1) // lcm(large, small)
 
numB = num_B_1 + num_B_2 - num_B_3
numA = num_A_1 + num_A_2 - num_A_3
 
print((B-A+1) - (numB - numA))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
A, B, C, D = [int(i) for i in input().split()]

def lcm(a, b, gcd):
    return a * b // gcd

large = np.max([C, D])
small = np.min([C, D])

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

while small != 0:
    large, small = small, large % small
    print(large, small)
gcd = large

large = np.max([C, D])
small = np.min([C, D])


num_B_1 = B // C
num_B_2 = B // D
num_B_3 = B // lcm(large, small, gcd)

num_A_1 = (A-1) // C
num_A_2 = (A-1) // D
num_A_3 = (A-1) // lcm(large, small, gcd)

numB = num_B_1 + num_B_2 - num_B_3
numA = num_A_1 + num_A_2 - num_A_3

print((B-A+1) - (numB - numA))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
A, B, C, D = [int(i) for i in input().split()]

large = np.max([C, D])
small = np.min([C, D])
g = large
while small != 0:
    large, small = small, large % small

g = large

l = C * D // g

num_B_1 = math.floor(B / C)
num_B_2 = math.floor(B / D)
num_B_3 = math.floor(B / l)
num_B = B - (num_B_1 + num_B_2 - num_B_3)

num_A_1 = math.floor((A - 1) / C)
num_A_2 = math.floor((A - 1) / D)
num_A_3 = math.floor((A - 1) / l)
num_A = (A - 1) - (num_A_1 + num_A_2 - num_A_3)

print(num_B - num_A)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
A, B, C, D = [int(i) for i in input().split()]

large = np.max([C, D])
small = np.min([C, D])
g = large
while small != 0:
    large, small = small, large % small

g = large

l = C / g * D

num_B_1 = math.floor(B / C)
num_B_2 = math.floor(B / D)
num_B_3 = math.floor(B / l)
num_B = B - (num_B_1 + num_B_2 - num_B_3)

num_A_1 = math.floor((A - 1) / C)
num_A_2 = math.floor((A - 1) / D)
num_A_3 = math.floor((A - 1) / l)
num_A = (A - 1) - (num_A_1 + num_A_2 - num_A_3)

print(num_B - num_A)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
A, B, C, D = [int(i) for i in input().split()]

large = np.max([C, D])
small = np.min([C, D])
quo = large // small
rem = large % small
g = small
while rem != 0:
    large = small 
    small = rem
    quo = large // small
    rem = large % small

g = small
#print(g)

l = C / g * D

#num_B_1 = math.floor(B / C)
#num_B_2 = math.floor(B / D)
#num_B_3 = math.floor(B / l)
num_B_1 = B // C
num_B_2 = B // D
num_B_3 = B // l
num_B = B - (num_B_1 + num_B_2 - num_B_3)

#num_A_1 = math.floor((A - 1) / C)
#num_A_2 = math.floor((A - 1) / D)
#num_A_3 = math.floor((A - 1) / l)
num_A_1 = (A - 1) // C
num_A_2 = (A - 1) // D
num_A_3 = (A - 1) // l
num_A = (A - 1) - (num_A_1 + num_A_2 - num_A_3)

print(num_B - num_A)