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:
import fractions

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

G = C*D // fractions.gcd(C,D)

Conly = 1 + ( ( ( B - (B%C) ) - ( A + C - (A%C) ) ) // C )
Donly = 1 + ( ( ( B - (B%D) ) - ( A + D - (A%D) ) ) // D )
CandD = 1 + ( ( ( B - (B%G) ) - ( A + G - (A%G) ) ) // G )

if C == 1 or D == 1:
  result = 0
else:
  result = B - A + 1 - ( Conly + Donly - CandD )
  
if B == C or B == D:
  result -= 1

print(result)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
def main():
    A,B,C,D = map(int,input().split())
    E = C*D
    Cc = B / C
    Dd = B / D
    Ee = B / E
    flo = A-1
    Cf = flo / C
    Df = flo / D
    Ef = flo / E
    All = B-(math.floor(Cc)+math.floor(Dd)-math.floor(Ee))
    Sub = flo-(math.floor(Cf)+math.floor(Df)-math.floor(Ef))
    print(All - Sub)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
gene = B-A+1
def gcd(x,y):
    X = max(x,y)
    Y = min(x,y)
    if Y == 0:
        return X
    else:
        return gcd(Y,X%Y)
ans = gene-(gene//C+gene//D-gene*gcd(C,D)//(C*D))
if C != D:
    if  (B % C == 0) ^ (B % D == 0):
        if (A % C == 0) ^ (A % D == 0):
            print(ans)
        else:
            print(ans-1)
    else:
        if (A % C == 0) ^ (A % D == 0):
            print(ans)
        else:
            print(ans-1)
else:
    print(gene-gene//C -1 if (B%C == 0)&(A%D == 0) else gene-gene//C)

Submission status: Wrong Answer

Solution code:
import math
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)



A,B,C,D = map(int,input().split())
CD = lcm(C, D)
# print("CD:",CD)
# print(" ===C====",math.ceil(A/C),math.floor(B/C))
# print(A/C,B/C)
# print(" ===D====",math.ceil(A/D),math.floor(B/D))
# print(A/D,B/D)
# print(" ===CD====",math.ceil(A/CD),math.floor(B/CD))
# print(A/CD,B/CD)


Cwari = math.floor(B/C) - math.ceil(A/C) +1
# print("Cwari:",Cwari)

Dwari = math.floor(B/D) - math.ceil(A/D)+1
# print("Dwari:",Dwari)

if CD >B :
    CDwari = 0
    # print("CDwari:",CDwari)
else:
    CDwari = math.floor(B/CD) - math.ceil(A/CD)+1
    # print("CDwari:",CDwari)


print(B-A+1-(Cwari+Dwari-CDwari))

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

# A以上B以下の数でXの倍数の個数
def countX(X) :
    if X > B :
        return 0
    minX = max(math.ceil(A / X),0)
    maxX = max(math.floor(B / X),0)
    return maxX - minX + 1

if C == 1 or D == 1 :
    print(0)
elif min(C,D) > B :
    print(A - B + 1)
elif max(C,D) % min(C,D) == 0 :
    Z = min(C,D)
    ans = B - A + 1 - countX(Z)
    print(ans + 1)
else :
    ans = B - A + 1

    # 最小公倍数
    Z = int(C * D / fractions.gcd(C,D))

    ans -= countX(C)
    ans -= countX(D)
    ans += countX(Z)

    print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d= map(int,input().split())
def gcd(c,d):
    while d!=0:
        c,d=d,c%d
    return c


def lcm(c,d):
    return c*d//gcd(c,d)

a1=0
a2=0
b1=0
b2=0
e1=0
e2=0


e=(c*d)/gcd(c,d)

if(a-1>=c):
    a1=(a-1)//c
else:
    a1=0

if(b>=c):
    b1=b//c
else:
    b1=0

if(a-1>=d):
    a2=(a-1)//d
else:
    a2=0

if(b>=d):
    b2=b//d
else:
    b2=0

if(a-1>=e):
    e1=(a-1)//e
else:
    e1=0

if(b>=e):
    e2=b//e
else:
    e2=0
        
ans=b-a+1-(b1-a1)-(b2-a2)+(e2-e1)

print(ans)

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc131/tasks/abc131_c

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

a,b,c,d = [int(i) for i in input().split()]
C = 0
D = 0
E = 0
'''
for i in range(int(a / max(c,d,lcm(c,d))),b-a):
    print(i)
    if c * i >= a and c * i <= b and C == 0:
        C = c * i
    if d * i >= a and d * i <= b and D == 0:
        D = d * i
    if lcm(c,d) * i >= a and lcm(c,d) * i <= b and E == 0:
        E = lcm(c,d) * i
    if C != 0 and D != 0 and E != 0:
        break
'''
'''
for i in range(int(a / lcm(c,d)) - 1,int(b / lcm(c,d))+2):
    if lcm(c,d) * i >= a and lcm(c,d) * i <= b and E == 0:
        E = lcm(c,d) * i
        break

for i in range(int(a / c) - 1,int(b / c)+2):
    if c * i >= a and c * i <= b and C == 0:
        C = c * i
        break

for i in range(int(a / d) - 1,int(b / d)+2):
    if d * i >= a and d * i <= b and D == 0:
        D = d * i
        break
'''
#print(lcm(c,d))
#print('')
#print(C,D,E)
'''
c2 = int(b / c) - int(C / c)+1
d2 = int(b / d) - int(D / d)+1
e2 = int(b / lcm(c,d)) - int(E / lcm(c,d))+1
'''
'''
if int(b / c) == b/c:
	print('c')
	c2 += 1
if int(b / d) == b/d:
	print('d')
	d2 += 1
if int(b / lcm(c,d)) == b/lcm(c,d):
	print('e')
	e2 += 1
'''
c2 = int(b / c) - int(a / c)
d2 = int(b / d) - int(a / d)
e2 = int(b / lcm(c,d)) - int(a / lcm(c,d))
if int(a / c) == a/c:
	#print('c')
	c2 += 1
if int(a / d) == a/d:
	#print('d')
	d2 += 1
if int(a / lcm(c,d)) == a/lcm(c,d):
	#print('e')
	e2 += 1
'''
if E == 0:
	e2 = 0
if C == 0:
	c2 = 0
if D == 0:
	d2 = 0
'''

#print(b-a+1,c2,d2,e2)
'''
c1 = list(range(C,b+1,c))
d1 = list(range(D,b+1,d))
e1 = list(range(E,b+1,lcm(c,d)))
print(b-a+1,len(c1),len(d1),len(e1))

print(c1,d1,e1)

print(b-a+1-len(c1)-len(d1)+len(e1))
'''
print(int(b-a+1 - c2 - d2 + e2))

Submission status: Wrong Answer

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

a, b, c, d = map(int, input().split())
num = 0
cd = c*d/(gcd(c,d))
s = b - a + 1
s_c = int(s/c)
s_d = int(s/d)
s_cd = int(s/cd)
if(a%c > b%c):
  num = num + 1
elif(a%c == b%c and a%c == 0):
  num = num + 1
if(a%d > b%d):
  num = num + 1
elif(a%d == b%d and a%d == 0):
  num = num + 1
if(a%cd > b%cd):
  num = num - 1
elif(a%cd == b%cd and a%cd == 0):
  num = num - 1
print(s -(s_c + s_d - s_cd) - num)

Submission status: Wrong Answer

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

k=a
p=a
q=a

n=0
m=0
h=0

for i in range(b-k):
    if k%(c*d)==0:
        n += 1
    k = k+1

for i in range(b-p):
    if p%c==0:
        m += 1
    p = p+1


for i in range(b-q):
    if q%d==0:
        h += 1
    q = q+1

print(b-a-(h+m-n)+1)

Submission status: Wrong Answer

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


a=set(range(A,B+1))
b=set()
c=set()
for i in range(1,B):
    if C*i>B and D*i>B:
        break
    b.add(C*i)
    c.add(D*i)
s = c | b
v = s & a
print(len(a)-len(v))

Submission status: Wrong Answer

Solution code:
import fractions

A, B, C, D = map(int,input().split())
CD = int(C * D / fractions.gcd(C, D))
numC = int(B/C) - int((A-1)/C)
numD = int(B/D) - int((A-1)/D)
numCD = int(B/(CD)) - int((A-1)/(CD))
print(B - A + 1 - (numC + numD - numCD))

Submission status: Wrong Answer

Solution code:
import fractions

parents = list(map(int,input().split(' ')))
All = parents[1] - parents[0]
min_2 = (parents[2]*parents[3]) // fractions.gcd(parents[2], parents[3])

All = All-All//parents[2]-All//parents[3]+All//min_2

if parents[2]>=parents[0] and parents[2]<=parents[1] and parents[2]>=(parents[1]-parents[0]):
    All = All-1
if parents[3]>=parents[0] and parents[3]<=parents[1] and parents[3]>=(parents[1]-parents[0]):
    All = All-1

if All<0:
    All = 0
print(All)

Submission status: Wrong Answer

Solution code:
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)

N_C = (B-A) // C
N_D = (B-A) // D
N_CD = (B-A) // lcm(C,D)
ans = 0
if C == 1:
    ans == 0
    print()
elif D == 1:
    ans == 0
else:
    ans = (B-A)-N_C-N_D+N_CD
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

from fractions import gcd
from math import ceil,floor

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


Cans = floor(B/C) - ceil(A/C) + 1
Dans = floor(B/D) - ceil(A/D) + 1

CD = C * D // gcd(C % D,D)
CDans = floor(B/CD) - ceil(A/CD) + 1

ans = (B-A+1) - (Cans + Dans - CDans)

print(ans)

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)

x =int((b-1)/c)-int((a/c))
y =int((b-1)/d)-int((a/d))
n =lcm(c,d)
xy=int(b/n)-int((a/n))

ans = (b-a+1) - (x+y-xy)
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
#cnt = 0
"""
c2 = b//c - a//c
d2 = b//d - a//d
cd = b//(c*d) - a//(c*d)
print(c2+d2-cd)
"""
a-=1
a2 = a//c + a//d - a//(c*d)
print(b-a-(b//c + b//d - b//(c*d) - a2))
"""
for i in range(a,b+1):
  if i % c != 0 and i % d != 0:
    cnt += 1
print(cnt)
"""

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split())
res = 0
for i in range(a,b+1):
  if i % c == 0 and i % d == 0:
    if a % (c*d) == 0 or b % (c*d) == 0:
      res -= 1
    res -= (b-i)//(c*d)
  elif i % c == 0:
    if a % c == 0 or b % c == 0:
      res += 1
    res += (b-i)//c
  else:
    if a % d == 0 or b % d == 0:
      res += 1
    res += (b-i)//d
    
print(res)

Submission status: Wrong Answer

Solution code:
import math
import fractions

A, B, C, D = map(int, input().split())
N = B - A + 1  #整数列の長さ

if C == D:
    tmp = 0   #最後にNから引く
    mod = A % C
    tmp += math.ceil((N-mod)/C)
    print(N-tmp)
elif fractions.gcd(C,D):
    tmp = 0   #最後にNから引く
    mod = A % C
    tmp += math.ceil((N-mod)/C)
    mod = A % D
    tmp += math.ceil((N-mod)/D)
    mod = A % (D*C)
    tmp -= math.ceil((N-mod)/(D*C))
    print(N-tmp)
else:
    tmp = 0   #最後にNから引く
    mod = A % min(C, D)
    tmp += math.ceil((N-mod)/min(C, D))
    print(N-tmp)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a % b
        return a
def lcm(a, b):
    return a * b // gcd (a, b)


number =str(input())
numbers = number.split(" ")
A = int(numbers[0])
B = int(numbers[1])
C = int(numbers[2])
D = int(numbers[3])

number = B - A + 1

answer_C = number / C

answer_D = number / D

answer_E = number / lcm(C,D)
final_answer = number - answer_C - answer_D + answer_E
print(int(final_answer))

Submission status: Wrong Answer

Solution code:
import math


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


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

AtoB = (B - (A - 1))

divisible_C = (B // C) - ((A - 1) // C)
divisible_D = (B // D) - ((A - 1) // D)

answer = 10
# minLcm = lcm(C, D)

# divisible_CD = (B // minLcm) - ((A - 1) // minLcm)
#
# divisible_CtoD = (divisible_C + divisible_D) - divisible_CD
#
# answer = AtoB - divisible_CtoD

print(answer)

Submission status: Wrong Answer

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

if B<C:
    if B<D:
        print(B-A+1)
    else:
        ist=(A-A%D)/D
        ien=(B-B%D)/D
        print(B-A+1-ien+ist-1)
elif B<D:
    ist=(A-A%C)/C
    ien=(B-B%C)/C
    print(B-A+1-ien+ist-1)
else:
    ist,ien,jst,jen,kst,ken=1,1,1,1,1,0
    ist=(A-A%C)/C
    ien=(B-B%C)/C
    jst=(A-A%D)/D
    jen=(B-B%D)/D
    ist=(A-A%(C*D))/(C*D)
    ien=(B-B%(C*D))/(C*D)
    print(B-A+1-ien+ist-1-jen+jst-1+ken-kst+1)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

def xc(x,C=C,D=D,CD=CD):
    return(x//C+x//D-x//(CD))

if B//C ==0 and B//D == 0:
    print(0)
else:
    print(B-A+1-xc(B+1)+xc(A))

Submission status: Wrong Answer

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

i = (b//c- a//c)
j = (b//d- a//d)

f=fractions.gcd(c,d)
f2= c * d / f
k = b//f2 - a//f2

count = int(i + j - k)

print(b-a+1-count)

Submission status: Wrong Answer

Solution code:
import fractions

parents = list(map(int,input().split(' ')))
All = parents[1] - parents[0]
min_2 = (parents[2]*parents[3]) // fractions.gcd(parents[2], parents[3])

All = All-All//parents[2]-All//parents[3]+All//min_2

if parents[2]>=parents[0] and parents[2]<=parents[1] and parents[2]>(parents[1]-parents[0]):
    All = All-1
if parents[3]>=parents[0] and parents[3]<=parents[1] and parents[3]>(parents[1]-parents[0]):
    All = All-1

if All<0:
    All = 0
print(All)

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
if c==1:
  print(0)
elif d==1:
  print(0)
else:
  cd = int(c*d/fractions.gcd(c, d))
  waru_c = int(b/c)-int((a-1)/c)
  waru_d = int(b/d)-int((a-1)/d)
  waru_cd = int(b/cd)-int((a-1)/cd)
  print((b-a+1)-(waru_c+waru_d-waru_cd))

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x

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

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

Submission status: Wrong Answer

Solution code:
a = [int(i) for i in input().split()]
num = {i for i in range(a[0],a[1]+1)}

import math
s_c = math.floor(a[0]/a[2])
e_c = math.floor(a[1]/a[2])
s_d = math.floor(a[0]/a[3])
e_d = math.floor(a[1]/a[3])
c_set = {i*2 for i in range(s_c,e_c+1)}
d_set = {i*3 for i in range(s_d,e_d+1)}

union = c_set | d_set
answer = num-union
print(len(answer))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math

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

A, B, C, D = map(int, input().split())
subst = abs(A - B)
num1 = subst // C + 1
num2 = subst // D + 1
num3 = subst // (C * D // gcd(C, D)) + 1

print(subst - num1 - num2 + num3 + 1)

Submission status: Wrong Answer

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

def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

lcm = C*D / gcd(C,D)
AC = A//C
AD = A//D
A_lcm = A//lcm
A_num = AC+AD-A_lcm

BC = B//C
BD = B//D
B_lcm = B//lcm
B_num = BC+BD-B_lcm

if (A%C) * (A%D) == 0:
  print(int((B-A) - (B_num-A_num)))
else:
  print(int((B-A) - (B_num-A_num) + 1))

Submission status: Wrong Answer

Solution code:
import math
import fractions

A,B,C,D=map(int,input().split())
A=A-1
G=int(fractions.gcd(C,D))
#print(G)

MM=((B//C)+(B//D)-int(B//(C*D/G)))
NN=((A//C)+(A//D)-int(A//(C*D/G)))
#print(MM,NN)
#print(B-MM)
#print(A-NN)
#print((B-MM)-(A-NN))  
GG=((B-MM)-(A-NN)) 
print(int(GG))

Submission status: Wrong Answer

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

MofD = 0
MofCD = 0

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

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


def sten(st, en, x):
    if x == 1:
        return en - st + 1
    st = math.ceil(st/x)*x
    en = math.floor(en/x)*x
    if en >= st:
        n = (en - st) // x + 1
    else:
        n = 0
    return n


MofC = sten(A, B, C)
if C != D:
    MofD = sten(A, B, D)
    MofCD = sten(A, B, lcm(C, D))

print(U-MofC-MofD+MofCD)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
if A%C==0 and A%D==0:
    C_div = (B-A+1)//C + 1
else:
    C_div = (B-A+1)//C
if B%C==0 or B%D==0:
    D_div = (B-A+1)//D + 1
else:
    D_div = (B-A+1)//D
if A%(C*D) == 0 or B%(C*D) == 0:
    CD_div = (B-A+1)//(C*D) + 1
else:
    CD_div = (B-A+1)//(C*D)
if C == 1 or D == 1:
    print(0)
elif C == D:
    print((B-A+1) - C_div)
elif C%D==0 or D%C==0:
    if C > D:
        print((B-A+1) - D_div)
    else:
        print((B-A+1) - C_div)
else:
    print((B-A+1) - C_div -D_div + CD_div)

Submission status: Wrong Answer

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

def countNum(nSmall, nLarge, nD):
    # find smaller than nLarge
    largest = math.floor(nLarge / nD) * nD
    smallest = math.ceil(nSmall / nD) * nD

    if largest == 0:
        return 0
    if smallest > largest:
        return 0
    return (largest-smallest) / nD + 1

numC = countNum(A,B,C)
numD = countNum(A,B,D)
numCD = countNum(A,B,(C*D)/fractions.gcd(C,D) )

able = numC + numD - numCD
print(B - A + 1 - able)

Submission status: Wrong Answer

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

s=c*d//fractions.gcd(c, d)
bk=0
ak=0
ans=0
bc=b//c
ac=a//c    
bd=b//d
ad=a//d
bsa=b//s
asa=a//s
bk=b-bc-bd+bsa
ak=a-ac-ad+asa
ans=bk-ak
if a%c!=0 or a%d!=0 or b%c!=0 or b%d!=0:
    print(ans+1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
p = 0
cntC = int(B / C) - int(A / C)
if A % C == 0:
    cntC += 1
cntD = int(B / D) - int(A / D)
if A % D == 0:
    cntD += 1

#a,bの最大公約数
def gcd(C, D):
    while D:
        C, D = D, C % D
    return C

#a,bの最小公倍数
def lcm(C, D):
    return C * D // gcd (C, D)


CD = lcm(C, D)

cntCD = int(B / CD) - int(A / CD)

# print(cntC, cntD, cntCD, CD)
calc = (B-A+1) - (cntC + cntD - cntCD)

if A % C == 0:
    p += 1


print(calc)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a % b
        return a
def lcm(a, b):
    return a * b // gcd (a, b)


number =str(input())
numbers = number.split(" ")
A = int(numbers[0])
B = int(numbers[1])
C = int(numbers[2])
D = int(numbers[3])

number = B - A + 1

answer_C = number / C

answer_D = number / D

answer_E = number / lcm(C,D)
final_answer = number - answer_C - answer_D + answer_E
final_answer = int(final_answer)
print(final_answer)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a, b):
	return a * b // gcd (a, b)
A, B, C, D = map(int, input().split())
diff = B - A + 1
count_c = int(B/C) - int((A-1)/C)
count_d = int(B/D) - int((A-1)/D)
cd = lcm(C,D)
count_cd = int(B/cd) - int((A-1)/cd)
print(diff - count_c - count_d + count_cd)

Submission status: Wrong Answer

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

l = raw_input().split()

a = int(l[0])
b = int(l[1])
c = int(l[2])
d = int(l[3])

lcm = ((c*d)//(gcd(c,d)))

div = []

div.append((a-1)/c)
div.append((a-1)/d)

div.append(b/c)
div.append(b/d)

div.append(a/lcm)
div.append(b/lcm)

ans =  (div[2]-div[0])+(div[3]-div[1])-(div[5]-div[4])
ans = (b-a+1) - ans

print ans

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

a = input().split(" ")

A = int(a[0])
B = int(a[1])
C = int(a[2])
D = int(a[3])

min = min(C,D)
max = max(C,D)

gcd = lcm(min,max)

c_num = 0
if A%min == 0:
     c_num = int(B/min) - int(A/min) + 1
else:
    c_num = int(B/min) - int(A/min)

d_num = 0
if A%max == 0:
     d_num = int(B/max) - int(A/max) + 1
else:
    d_num = int(B/max) - int(A/max)


gcd_num = 0
if A%gcd == 0:
     gcd_num = int(B/gcd) - int(A/gcd) + 1
else:
    gcd_num = int(B/gcd) - int(A/gcd)


print(B-A+1-c_num-d_num+gcd_num)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

# A以上B以下の数でXの倍数の個数
def countX(X) :
    if X > B :
        return 0
    minX = max(math.ceil(A / X),0)
    maxX = max(math.floor(B / X),0)
    return maxX - minX + 1

if C == 1 or D == 1 :
    print(0)
elif min(C,D) > B :
    print(A - B + 1)
elif max(C,D) % min(C,D) == 0 :
    Z = min(C,D)
    ans = B - A + 1 - countX(Z)
    print(ans)
else :
    ans = B - A + 1

    # 最小公倍数
    Z = int(C * D / fractions.gcd(C,D))

    ans -= countX(C)
    ans -= countX(D)
    ans += countX(Z)

    print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
import math
import fractions
num_C = math.floor(B/C) - math.ceil(A/C) + 1
num_D = math.floor(B/D) - math.ceil(A/D) + 1
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
lcm_C_D = lcm(C, D)
num_C_D = math.floor(B/lcm_C_D) - math.ceil(A/lcm_C_D) + 1
ans = (B - A +1) - (num_C + num_D - num_C_D)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a

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

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

lcm = lcm(C, D)

minc = C*math.ceil(A/C)
maxc = C*math.floor(B/C)
mind = D*math.ceil(A/D)
maxd = D*math.floor(B/D)
minlcm = lcm*math.ceil(A/lcm)
maxlcm = lcm*math.floor(B/lcm)

nc = int( ( (maxc - minc)/C ) + 1 )
nd = int( ( (maxd - mind)/D ) + 1 )
nlcm = int( ( (maxlcm - minlcm)/lcm ) + 1 )

if C > B:
    nc = 0
if D > B:
    nd = 0
if lcm > B:
    nlcm = 0

n = B - A + 1 - nc - nd + nlcm

print(n)

Submission status: Wrong Answer

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

from fractions import gcd


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


def mm(a, b, n):
    if a + n > b:
        return 0
    z = a + n - a % n
    return (B - z) // n


E = lcm(C, D)
tc = mm(A, B, C)
td = mm(A, B, D)
te = mm(A, B, E)

print(B - A - (tc + td - te))

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 = math.ceil((B / C) - (A / C))
b = math.ceil((B / D) - (A / D))
c = lcm(C, D)
d = 0
d += c
while d < A:
    d += c
tmp = 0
while d <= B:
    d += c
    tmp += 1
print(B - A + 1 - (a + b - tmp))

Submission status: Wrong Answer

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

def wareruzu(x):
    if b < x:
        return 0
    start_a = a if a % x == 0 else a - (a % x) + x
    end_b = b - (b % x)
    m = end_b - start_a 
    return int(m / x) + 1 if end_b <= start_a else int(m / x)

all_n = b - a + 1
print(all_n - wareruzu(c) - wareruzu(d) + wareruzu((c*d) / fractions.gcd(c,d)))

Submission status: Wrong Answer

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

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

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

lcm_num = lcm(c,d)
c_num = (b//c - a//c) if a%c!=0 else (b//c - a//c + 1)
d_num = (b//d - a//d) if a%d!=0 else (b//d - a//d + 1)
ba_num = b//lcm_num - a//lcm_num

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

Submission status: Wrong Answer

Solution code:
def gcd(a, b):

    while b:

        a, b = b, a % b

    return a

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

X = (C * D) // gcd(C, D)
Y = (C + D) // gcd(C, D) - 1

#print(X,Y)

N = A % X 
N_S = N-1
UA = Y - (N_S // C + N_S // D)

#print(UA)
M = B % X
UB = M // C + M // D 

#print(UB)


SA =  A + ( X - N )
SB =  B - M 
#print(SA,SB)
count = (SB - SA) // X * Y 

#print(count)
add = count + UA + UB
    
Z = B - A - add + 1

if X == 1:
    Z = 0
print(Z)

Submission status: Wrong Answer

Solution code:
import fractions

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

e=((c * d) // fractions.gcd(c, d))
f=a-1

g = int(b/c) + int(b/d) - int(b/e)
h = int(f/c) + int(f/d) - int(f/e)
print(b - a + 1 - g + h)

Submission status: Wrong Answer

Solution code:
import fractions
a = list(map(int, input().split()))
if a[0]==a[1]:
    if a[0]%a[2]==0 or a[0]%a[3]==0:
        print(0)
    else:
        print(1)
else:
    n = a[1]-a[0]+1
    wac = int(a[1]/a[2])-int(a[0]/a[2])

    if a[0]%a[2]==0:
        wac+=1
    wad= int(a[1]/a[3])-int(a[0]/a[3])

    if a[0]%a[3]==0:
        wad+=1
        
    lcm = a[2]*a[3]//fractions.gcd(a[2], a[3])
    cd = int(a[1]/lcm)-int(a[0]/lcm)

    if a[0]%lcm==0:
        cd +=1

    print(n-wac-wad+cd)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):#Euclidean Algorithm
    while (b!= 0):
        a,b=b,a%b
    return a

l = raw_input().split()

a = int(l[0])
b = int(l[1])
c = int(l[3])
d = int(l[2])
#if(c>d):
#    c = int(l[3])
#    d = int(l[2])

lcm = ((c*d)//(gcd(c,d)))

div = []

div.append((a-1)/c)
div.append((a-1)/d)

div.append(b/c)
div.append(b/d)

div.append(a/lcm)
div.append(b/lcm)

ans =  (div[2]-div[0])+(div[3]-div[1])-(div[5]-div[4])
ans = (b-a+1) - ans

print ans

Submission status: Wrong Answer

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


a=set(range(A,B+1))
b=set()
c=set()
for i in range(1,B):
    if C*i>B and D*i>B:
        break
    b.add(C*i)
    c.add(D*i)
print(c)
print(b)

s = c | b
v = s & a
print(s)
print(len(a)-len(v))

Submission status: Wrong Answer

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

if B<C:
    if B<D:
        print(B-A+1)
    else:
        ist=(A-A%D)/D
        ien=(B-B%D)/D
        print(B-A+1-ien+ist-1)
elif B<D:
    ist=(A-A%C)/C
    ien=(B-B%C)/C
    print(B-A+1-ien+ist-1)
else:
    ist,ien,jst,jen,kst,ken=1,1,1,1,1,0
    ist=(A-A%C)/C
    ien=(B-B%C)/C
    jst=(A-A%D)/D
    jen=(B-B%D)/D
    ist=(A-A%(C*D))/(C*D)
    ien=(B-B%(C*D))/(C*D)
    print(B-A+1-ien+ist-1-jen+jst-1+ken-kst+1)
            
    
if B<C:
    if B<D:
        print(int(B-A+1))
    else:
        ist=(A-A%D)/D
        ien=(B-B%D)/D
        print(int(B-A+1-ien+ist-1))
elif B<D:
    ist=(A-A%C)/C
    ien=(B-B%C)/C
    print(int(B-A+1-ien+ist-1))
else:
    ist,ien,jst,jen,kst,ken=1,1,1,1,1,0
    ist=(A-A%C)/C
    ien=(B-B%C)/C
    jst=(A-A%D)/D
    jen=(B-B%D)/D
    ist=(A-A%(C*D))/(C*D)
    ien=(B-B%(C*D))/(C*D)
    print(int(B-A+1-ien+ist-1-jen+jst-1+ken-kst+1))

Submission status: Wrong Answer

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

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

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

count = 0
for _ in range(a//c, (b+1)//c):
    count += 1
for _ in range(a//d, (b+1)//d):
    count += 1
for _ in range(a//lcm(c,d), (b+1)//lcm(c,d)):
    count -= 1

print(b+1-a-count)

Submission status: Wrong Answer

Solution code:
import math


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


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

AtoB = (B - (A - 1))

divisible_C = (B // C) - ((A - 1) // C)
divisible_D = (B // D) - ((A - 1) // D)

answer = 10
# minLcm = lcm(C, D)
# 
# divisible_CD = (B // minLcm) - ((A - 1) // minLcm)
# 
# divisible_CtoD = (divisible_C + divisible_D) - divisible_CD
# 
# answer = AtoB - divisible_CtoD

print(answer)

Submission status: Wrong Answer

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

def countNum(nSmall, nLarge, nD):
    # find smaller than nLarge
    largest = (nLarge // nD) * nD
    smallest = math.ceil(nSmall / nD) * nD

    if largest == 0:
        return 0
    if smallest > largest:
        return 0
    return (largest-smallest) // nD + 1

numC = countNum(A,B,C)
numD = countNum(A,B,D)
numCD = countNum(A,B,(C*D)//fractions.gcd(C,D) )

able = numC + numD - numCD
print(B - A + 1 - able)

Submission status: Wrong Answer

Solution code:
import sys
def gcd(x, y):
  if x%y:
  	return gcd(y, x%y)
  else:
    return y
  
a,b,c,d = list(map(int,input().split()))

if (c==1)|(d==1):
  print(0)
  sys.exit()
ac = a//c
bc = b//c
ad = a//d
bd = b//d

o = max(c, d)
p = min(c, d)

gcd_ = gcd(o,p)
lcm = int(c*d/gcd_)

acd = a//lcm
bcd = b//lcm

print(int(b-a+1-(bc-ac+bd-ad-(bcd-acd))))

Submission status: Wrong Answer

Solution code:
import fractions

parents = list(map(int,input().split(' ')))
All = parents[1] - parents[0]
min_2 = (parents[2]*parents[3]) // fractions.gcd(parents[2], parents[3])

All = All-All//parents[2]-All//parents[3]+All//min_2

if parents[2]>=parents[0] and parents[2]<=parents[1] and parents[2]<=(parents[1]-parents[0]):
    All = All-1
if parents[3]>=parents[0] and parents[3]<=parents[1] and parents[3]<=(parents[1]-parents[0]):
    All = All-1

if All<0:
    All = 0
print(All)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from math import ceil, floor
from fractions import gcd
A, B, C, D = map(int, input().split())
lcm = (C * D) // gcd(C, D)
# c_cnt = ceil((B) / C) - (A-1) // C
# d_cnt = ceil((B) / D) - (A-1) // D
# cd_cnt = ceil((B) / (lcm)) - (A-1) // (lcm)
c_cnt = (B+1) // C - (A-1) // C
d_cnt = (B+1) // D - (A-1) // D
cd_cnt = (B+1) // (lcm) - (A-1) // (lcm)
minus = c_cnt + d_cnt - cd_cnt
# print(c_cnt, d_cnt, cd_cnt)
print(B - A - minus + 1)

Submission status: Wrong Answer

Solution code:
a, b, c ,d = map(int, input().split())
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def lcm(a,b):
      return a*b//gcd(a,b)
e = lcm(c, d)
wareru = (int(b/c) + int(b/d) - int(b/e)) - (int((a-1)/c) + int((a-1)/d) - int((a-1)/e))
print(b-a+1-wareru)

Submission status: Wrong Answer

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


def gcd(x, y):
    x = abs(x)
    y = abs(y)
    while y:
        x, y = y, x % y
    return x

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

def Ndivingcd(x, y, i):
    if x==y:
        return i-(int)(i/x)
    else:
        return i - (int)(i / x) - (int)(i / y)

CDgcd = lcm(C,D)
Ningcd = 0
if C==D:
    Ningcd = CDgcd -1
else:
    Ningcd = CDgcd - (int)(CDgcd/C) - (int)(CDgcd/D) +1
Nloop = math.floor(B / CDgcd)-math.floor(A / CDgcd)
firstgcd = math.floor(A / CDgcd)*CDgcd
lastgcd  = math.floor(B / CDgcd)*CDgcd
NdivtoA=0
if not A==firstgcd:
    NdivtoA = Ndivingcd(C,D,A-firstgcd-1)
NdivtoB = Ndivingcd(C,D,B-lastgcd)
N = Nloop*Ningcd+NdivtoB-NdivtoA
print(N)

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D=map(int,input().split())
X=0
L=0
M=0
N=0
E=C*D//fractions.gcd(C,D)
if A%C==0 or B%C==0:
    L=(B-A)//C+1
else:
    L=(B-A)//C

if A%D==0 or B%D==0:
    M=(B-A)//D+1
else:
    M=(B-A)//D
if B-A>=E:
    if A%E==0 or B%E==0:
        N=(B-A)//E+1
    else:
        N=(B-A)//E
else:
    if B<E :
        N=0
    else :
        N=1
X=B-A+1-L-M+N
print(X)

Submission status: Wrong Answer

Solution code:
import fractions

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

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


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

AB = B-A
count = 0

firstC = int(A/C)
if A%C == 0:
    firstC -= 1
firstD = int(A/D)

if A%D == 0:
    firstD -= 1

firstCD = int(A/lcm(C,D))
if A%lcm(C,D) ==0:
    firstCD -= 1
    firstC +=1
    firstD +=1

endC = int(B/C)
endD = int(B/D)
endCD = int(B/lcm(C,D))

thereC = endC - firstC
thereD = endD - firstD
thereCD = endCD - firstCD

NoP = thereC+thereD - thereCD
#
# print(thereC)
# print(thereD)
# print(thereCD)
# print(NoP)

print(B-A+1-NoP)

Submission status: Wrong Answer

Solution code:
import fractions

parents = list(map(int,input().split(' ')))
All = parents[1] - parents[0]
min_2 = (parents[2]*parents[3]) // fractions.gcd(parents[2], parents[3])

All = All-All//parents[2]-All//parents[3]+All//min_2

if parents[2]>=parents[0] and parents[2]<=parents[1] and parents[2]<(parents[1]-parents[0]):
    All = All-1
if parents[3]>=parents[0] and parents[3]<=parents[1] and parents[3]<(parents[1]-parents[0]):
    All = All-1

if All<0:
    All = 0
print(All)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
gene = B-A+1
def gcd(x,y):
    X = max(x,y)
    Y = min(x,y)
    if Y == 0:
        return X
    else:
        return gcd(Y,X%Y)
ans = gene-(gene//C+gene//D-gene*gcd(C,D)//(C*D))
if  (B % C == 0) ^ (B % D == 0):
    if (A % C == 0) ^ (A % D == 0):
        print(ans)
    else:
        print(ans-1)
else:
    if (A % C == 0) ^ (A % D == 0):
        print(ans)
    else:
        print(ans-1)

Submission status: Wrong Answer

Solution code:
import math

line = input().split()

a = int(line[0])
b = int(line[1])
c = int(line[2])
d = int(line[3])

ran = b-a+1
c_c = ran//c
d_c = ran//d
cd_c = ran//(c*d)
rang = c_c+d_c-cd_c
result_c = ran - rang
  

print(result_c)