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:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]
 
n = 0
m = 0
nm = 0
 
 
for i in range(a,b):
  if i % c == 0:
    n =+ 1
    
    
for j in range(a,b):
  if j % d == 0:
    m =+ 1
 
    
for k in range(a,b):
  if (k % c == 0) and (k%d == 0):
    nm =+ 1
    
    
A = b - a + 1
B = n + m - nm
print(A-B)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

n = 0
m = 0
nm = 0


for i in range(a,b):
  if i % c == 0:
    n =+ 1
    
    
for j in range(a,b):
  if j % d == 0:
    m =+ 1

    
for k in range(a,b):
  if (k % c == 0) and (k%d == 0):
    nm =+ 1
    
    
A = a+b
B = n + m - nm
print(A-B)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

n = 0
m = 0
nm = 0
e = c*d

for i in range(a,b):
  if i % c == 0:
    n =+ 1
    
    
for j in range(a,b):
  if j % d == 0:
    m =+ 1

    
for k in range(a,b):
  if k % e == 0:
    nm =+ 1
    
    
A = a+b
B = n + m - nm
print(A-B)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

n = 0
m = 0
nm = 0

for i in range(a,b):
  if i % c == 0:
    n =+ 1
    
    
for j in range(a,b):
  if j % d == 0:
    m =+ 1

    
for k in range(a,b):
  if (k % c == 0) and (k % d == 0):
    nm =+ 1
    
    
A = a+b
B = n + m + nm
print(A-B)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

n = 0
m = 0
nm = 0

for i in range(a,b):
  if i % c == 0:
    n =+ 1
    
    
for j in range(a,b):
  if j % d == 0:
    m =+ 1

    
for k in range(a,b):
  if (k % c == 0) and (k % d == 0):
    nm =+ 1
    
    
print(n + m -nm)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

n = 0
m = 0
nm = 0
i = a
j = a
k = a

for i in range(a,b):
  if i % c == 0:
    n =+ 1
    
    
for j in range(a,b):
  if j % d == 0:
    m =+ 1

    
for k in range(a,b):
  if (k % c == 0) and (k % d == 0):
    nm =+ 1
    
    
print(n + m -nm)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

n = 0
m = 0
nm = 0
i = 0
j = 0
k = 0

for i in range(a,b):
  if i % c == 0:
    n =+ 1
    
    
for j in range(a,b):
  if j % d == 0:
    m =+ 1

    
for k in range(a,b):
  if (k % c == 0) and (k % d == 0):
    nm =+ 1
    
    
print(n + m -nm)

Submission status: Wrong Answer

Solution code:
#3

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

while y != 0:
	x,y =y,x%y
x = (c*d)//x

count1 = b - (b//c + b//d -b//x)
count2 = (a - 1) - (a//c + a//d -a//x) 

print(count1 - count2)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A,B,C,D=map(int,input().split())
X,Y=B-A+1,C*D//gcd(C,D)

print(int(X-X/C-X/D+X/Y))

Submission status: Wrong Answer

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

def count(x):
    return x - int(x/c) - int(x/d) + int(x/lcm(c,d))

print(count(b) - count(a-1))

Submission status: Wrong Answer

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

def count(x):
    return x - int(x/c) - int(x/d) + int(x/(c*d/gcd(c,d)))

print(count(b) - count(a-1))

Submission status: Wrong Answer

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


if (c > d) :
    y = c
    z = d
else :
    y = d
    z = c

while(True) :
    amari = y % z
    if(amari==0) :
        break
    y = z
    z = amari

cd = int (c * d / z)

wari1 = int(b/c) + int(b/d) - int(b/cd) 
wari2 = int((a-1)/c) + int((a-1)/d) - int((a-1)/cd) 


print(str(b - a - wari1 + wari2 + 1))

Submission status: Wrong Answer

Solution code:
import fractions
A, B, C, D = map(int, input().split(' '))
warizan = [ B//C - (A-1)//C, B//D - (A-1)//D, B//(C*D/fractions.gcd(C, D)) - (A-1)//(C*D/fractions.gcd(C, D))]
print(B-(A-1)-(warizan[0]+warizan[1]-warizan[2]))

Submission status: Wrong Answer

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

if (c > d) :
    y = c
    z = d
else :
    y = d
    z = c

while(True) :
    amari = y % z
    if(amari==0) :
        break
    y = z
    z = amari

cd = c * d /z

wari = (int(b/c) + int(b/d) - int(b/int(cd)) - (int((a-1)/c) + int((a-1)/d) - int((a-1)/int(cd) )))

print(str(b - a - wari + 1))

Submission status: Wrong Answer

Solution code:
import fractions
A, B, C, D = map(int, input().split(' '))
warizan = [ B//C - (A-1)//C, B//D - (A-1)//D, int(B//(C*D/fractions.gcd(C, D)) - (A-1)//(C*D/fractions.gcd(C, D)))]
print(B-(A-1)-(warizan[0]+warizan[1]-warizan[2]))

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split(' '))
warizan = [ B//C - (A-1)//C, B//D - (A-1)//D, int(B//(C*D) - (A-1)//(C*D))]
print(B-(A-1)-(warizan[0]+warizan[1]-warizan[2]))

Submission status: Wrong Answer

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

warizan = [B//C - (A-1)//C, B//D - (A-1)//D, B//(C*D) - (A-1)//(C*D)]

print(B-(A-1)-(warizan[0]+warizan[1]-warizan[2]))

Submission status: Wrong Answer

Solution code:
import fractions

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

def howmany(num, div1, div2):
  tsumugi = num // div1
  matsuri = num // div2
  kaori = num // (div1 * div2 //fractions.gcd(div1, div2))
  mizuki = num - tsumugi - matsuri + kaori
  return mizuki

A = howmany(a, c, d)
B = howmany(b, c, d)

ans = B - A

print(ans)

Submission status: Wrong Answer

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

import fractions

def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        x, y = y, x % y
    return x
'''
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 = b // c - (a-1) // c
d2 = b // d - (a-1) // d
e2 = b // (c*d/gcd(c,d)) - (a-1)//(c*d/gcd(c,d))
'''
if a % c == 0:
	#print('c')
	c2 += 1
if a % d == 0:
	#print('d')
	d2 += 1
if a % lcm(c,d) == 0:
	#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:
import math,fractions
a=list(map(int,input().split()))
A=a[1]-a[0]+1
B=math.floor(a[1]/a[2])-math.floor(a[0]/a[2])
if a[0]/a[2]==a[0]/a[2]:
  B+=1
C=math.floor(a[1]/a[3])-math.floor(a[0]/a[3])
d=a[2]*a[3]/fractions.gcd(a[2],a[3])
D=math.floor(a[1]/d)-math.floor(a[0]/d)
print(A-B-C+D)

Submission status: Wrong Answer

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

Cu = B//C       #Cの上限
Cd = -(-A//C)   #Cの下限
Du = B//D       #Dの上限
Dd = -(-A//D)   #Dの下限

#Least common multiple
LCMu = B//(C*D)
LCMd = -(-A//(C*D))

C_num = Cu - Cd + 1
D_num = Du - Dd + 1
LCM_num = LCMu - LCMd + 1

C_D_num = C_num + D_num - LCM_num
A_B_num = B - A  + 1

ans = A_B_num - C_D_num
print(ans)

Submission status: Wrong Answer

Solution code:
import math,fractions
a=list(map(int,input().split()))
A=a[1]-a[0]+1
B=math.floor(a[1]/a[2])-math.floor(a[0]/a[2])
if a[0]/a[2]==a[0]//a[2]:
  B+=1
C=math.floor(a[1]/a[3])-math.floor(a[0]/a[3])
d=a[2]*a[3]/fractions.gcd(a[2],a[3])
D=math.floor(a[1]/d)-math.floor(a[0]/d)
print(A-B-C+D)

Submission status: Wrong Answer

Solution code:
import math,fractions
a=list(map(int,input().split()))
A=a[1]-a[0]+1
B=math.floor(a[1]/a[2])-math.floor(a[0]/a[2])
if a[0]==math.floor(a[0]/a[2])*a[2]:
  B+=1
C=math.floor(a[1]/a[3])-math.floor(a[0]/a[3])
d=a[2]*a[3]/fractions.gcd(a[2],a[3])
D=math.floor(a[1]/d)-math.floor(a[0]/d)
print(A-B-C+D)

Submission status: Wrong Answer

Solution code:
import math,fractions
a=list(map(int,input().split()))
A=a[1]-a[0]+1
B=math.floor(a[1]/a[2])-math.floor(a[0]/a[2])
if a[0]==B*a[2]:
  B+=1
C=math.floor(a[1]/a[3])-math.floor(a[0]/a[3])
d=a[2]*a[3]/fractions.gcd(a[2],a[3])
D=math.floor(a[1]/d)-math.floor(a[0]/d)
print(A-B-C+D)

Submission status: Wrong Answer

Solution code:
import fractions as frac
[a,b,c,d] = [int(i) for i in input().split()]
e = c * d / frac.gcd(c,d)
a1 = (a-1) // c
a2 = (a-1) // d
a3 = (a-1) // e
b1 = b // c
b2 = b // d
b3 = b // e
print(int(b - a + 1 - ((b1+b2-b3) - (a1 + a2 - a3))))

Submission status: Wrong Answer

Solution code:
import fractions as frac
[a,b,c,d] = [int(i) for i in input().split()]
e = c * d / frac.gcd(c,d)
a1 = (a-1) // c
a2 = (a-1) // d
a3 = (a-1) // e
b1 = b // c
b2 = b // d
b3 = b // e
print(b - a + 1 - (-a1 - a2 + a3 - b3 + b1 + b2))

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

# 最大公約数
def lcm(x,y):
    return (x+y)//fractions.gcd(x,y)


def LI(): return list(map(int, sys.stdin.readline().split()))

A,B,C,D = LI()

upper_cnt = B - (B // C + B // D - B //lcm(D,C))
lower_cnt = A - (A // C + A // D - A //lcm(C,D))


print(upper_cnt-lower_cnt)

Submission status: Wrong Answer

Solution code:
import fractions as frac
[a,b,c,d] = [int(i) for i in input().split()]
e = c * d / frac.gcd(c,d)
a1 = (a-1) // c
a2 = (a-1) // d
a3 = (a-1) // e
b1 = b // c
b2 = b // d
b3 = b // e
print(b - a + 1 -a1 - a2 + a3 - b3 + b1 + b2)

Submission status: Wrong Answer

Solution code:
import fractions as frac
[a,b,c,d] = [int(i) for i in input().split()]
e = c * d / frac.gcd(c,d)
a1 = (a-1) // c
a2 = (a-1) // d
a3 = (a-1) // e
b1 = b // c
b2 = b // d
b3 = b // e
print(-a1 - a2 + a3 - b3 + b1 + b2)

Submission status: Wrong Answer

Solution code:
import fractions as frac
[a,b,c,d] = [int(i) for i in input().split()]
e = frac.gcd(c,d)
a1 = (a-1) // c
a2 = (a-1) // d
a3 = (a-1) // e
b1 = b // c
b2 = b // d
b3 = b // e
print(b - a + 1 -a1 - a2 + a3 - b3 + b1 + b2)

Submission status: Wrong Answer

Solution code:
import fractions as frac
[a,b,c,d] = [int(i) for i in input().split()]
e = frac.gcd(c,d)
a1 = (a-1) // c
a2 = (a-1) // d
a3 = (a-1) // e
b1 = (b) // c
b2 = (b) // d
b3 = (b) // e
print(-a1 - a2 + a3 - b3 + b1 + b2)

Submission status: Wrong Answer

Solution code:
import math
a=list(map(int,input().split()))
A=a[1]-a[0]+1
B=math.floor(a[1]/a[2])-math.floor(a[0]/a[2])
C=math.floor(a[1]/a[3])-math.floor(a[0]/a[3])
d=a[2]*a[3]
D=math.floor(a[1]/d)-math.floor(a[0]/d)
print(A-B-C+D)

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) # bより小さい最大の値。
    m = end_b - start_a
    return int(m / x) + 1
 
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:
import fractions as frac
[a,b,c,d] = [int(i) for i in input().split()]
e = frac.gcd(c,d)
a1 = (a-1) // c
a2 = (a-1) // d
a3 = (a-1) // e
b1 = (b-1) // c
b2 = (b-1) // d
b3 = (b-1) // e
print(-a1 - a2 + a3 - b3 + b1 + b2)

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) # bより小さい最大の値。
    m = end_b - start_a
    return m // x + 1
 
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:
import fractions
a, b, c, d = map(int, input().split())
 
def wareruzu(x):
    if b < x:
        return 0
    if b == x:
        return 1
    start_a = a if a % x == 0 else a - (a % x) + x
    end_b = b - (b % x) # bより小さい最大の値。
    m = end_b - start_a
    if m < 0:
        return 0
    return int(m / x) + 1
 
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:
import fractions as frac
[a,b,c,d] = [int(i) for i in input().split()]
e = c * d / frac.gcd(c,d)
a1 = (a-1) // c
a2 = (a-1) // d
a3 = (a-1) // e
b1 = (b-1) // c
b2 = (b-1) // d
b3 = (b-1) // e
print(-a1 - a2 + a3 - b3 + b1 + b2)

Submission status: Wrong Answer

Solution code:
import fractions

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

# l = lcm(c,d)
g = fractions.gcd(c, d)
l = int((c * d) / g)

def num(x, y, z): #x以上y以下でzで割り切れる数の個数
    ent = int((x - 1) / z)
    att = int(y / z)
    return att - ent

gyaku = num(a, b, c) + num(a, b, d) - num(a, b, l)
print(b - a + 1 - gyaku)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 23 14:44:36 2019

@author: Enya
"""

X = input()

A = int(X.split()[0])
B = int(X.split()[1])
C = int(X.split()[2])
D = int(X.split()[3])

# 最大公約数
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)



N_1 = (B // C) 
N_11 = (A-1) // C
N_2 = (B // D)
N_22 =((A-1) // D)
N_3 = (B // E)
N_33 = (A-1) // E

a = B - (N_1 + N_2 - N_3)
b= (A-1) - (N_11 + N_22 - N_33)




print(int(a-b))

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
 
def wareruzu(x):
    if b < x:
        return 0
    if b == x:
        return 1
    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
 
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:
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 23 14:44:36 2019

@author: Enya
"""

X = input()

A = int(X.split()[0])
B = int(X.split()[1])
C = int(X.split()[2])
D = int(X.split()[3])

# 最大公約数
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)


if A ==1: 
    N_1 = (B // C)
    N_2 = (B // D)
    N_3 = (B // E)

else:
    N_1 = (B // C) - ((A-1) // C)
    N_2 = (B // D) - ((A-1) // D)
    N_3 = (B // E) - ((A-1) // E)


N_4 = N_1 + N_2 - N_3
Bit = B - A + 1

print(int(Bit - N_4))

Submission status: Wrong Answer

Solution code:
def L(l,a,b):
    for i in l:
        if i>=a:
            index1=l.index(i)
            break
    for i in reversed(l):
        if i <b:
            index2=len(l)-1
            break
        elif i==b:
            index2= l.index(i)+1
            #print(index2)
            break
    if len(l) != 1:
        del l[index2:]
        del l[:index1]
    else:
        #del l[:index1]
        l.clear()
    return l

def l(l,b,x):
    i=0
    while i<=b:
        i+=x
        l.append(i)
    return l

a, b, c ,d = [int(i)  for i in input().split()]
l1,l2=[],[]
i=0
sub=b-a+1

l1,l2 = l(l1, b, c),  l(l2,b, d)
#print(l1,l2)

L1=L(l1, a,b)
L2=L(l2, a,b)

L2 = list(set(L2) - (set(L1) & set(L2)))

#print(L1, L2)

ans = sub-len(L1)-len(L2)
ans

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 23 14:44:36 2019

@author: Enya
"""

X = input()

A = int(X.split()[0])
B = int(X.split()[1])
C = int(X.split()[2])
D = int(X.split()[3])

# 最大公約数
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)

N_1 = (B // C) - ((A-1) // C)
N_2 = (B // D) - ((A-1) // D)
N_3 = (B // E) - ((A-1) // E)

N_4 = N_1 + N_2 - N_3
Bit = B - A + 1

print(int(Bit - N_4))

Submission status: Wrong Answer

Solution code:
import fractions,math

lis=list(map(int,input().split()))
gCD=fractions.gcd(lis[2],lis[3])
CD=int((lis[2]*lis[3])/gCD)
lis[0]=lis[0]-1
AC=math.floor(lis[0]/lis[2])
AD=math.floor(lis[0]/lis[3])
ACD=math.floor(lis[0]/CD)
BC=math.floor(lis[1]/lis[2])
BD=math.floor(lis[1]/lis[3])
BCD=math.floor(lis[1]/CD)
A=lis[0]-AC-AD+ACD
B=lis[1]-BC-BD+BCD
ans=B-A
print(ans)
#print(AC,AD,BC,BD,CD,ACD,BCD)
#print(lis)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
S = B - A + 1
def f(a,b):
    c = 0 if B%2 else 1
    return a//b + c
a=f(S,C)
b=f(S,D)
c=f(S,(C*D))
print(S - (a+b-c))

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
S = B - A + 1
a=S//C
b=S//D
c=S//(C*D)
print(S - (a+b-c))

Submission status: Wrong Answer

Solution code:
import fractions

input_line = input()
lines = input_line.split()
A = int(lines[0])
B = int(lines[1])
C = int(lines[2])
D = int(lines[3])
LCM = C * D / fractions.gcd(C,D)
#print('GCD',GCD)
num = B - A + 1
#print('num',num)
if C == D:
  c_dec = int(B / C)
  c_dec -= int(A / C)
  if A % C == 0:
    c_dec += 1
  d_dec = 0
  lcm_dec = 0
else:
  if LCM == D:
  	c_dec = 0
  else:
    c_dec = int(B / C)
    c_dec -= int(A / C)
    if A % C == 0:
      c_dec += 1
  if LCM == C:
    d_dec = 0
  else:
    d_dec = int(B / D)
    d_dec -= int(A / D)
    if A % D == 0:
      d_dec += 1
#print('d_dec',d_dec)
if LCM == C or LCM == D:
  lcm_dec = 0
else:
  lcm_dec = int(B / LCM)
  lcm_dec -= int(A / LCM)
  if A % LCM == 0:
    lcm_dec += 1
print(num - c_dec - d_dec + lcm_dec)

Submission status: Wrong Answer

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

import sys
sys.setrecursionlimit(1000000001)

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

def how_many(num):
    return int(B/num)-int((A-1)/num)

count -= how_many(C)
count -= how_many(D)
E = C * D / euclid(D, C)
count += how_many(E)

print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from collections import defaultdict
import math
import re

def compute_dividable_num(x, A, B):
    lower = math.ceil(A / x)
    upper = math.floor(B / x)

    num = upper - lower + 1
    return num

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

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

    C_num = compute_dividable_num(C, A, B)
    D_num = compute_dividable_num(D, A, B)

    CD = C // gcd(C, D) * D
    CD_num = compute_dividable_num(CD, A, B)

    C_or_D_num = C_num + D_num - CD_num

    num = (B - A + 1) - C_or_D_num

    print(num)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from collections import defaultdict
import math
import re

def compute_dividable_num(x, A, B):
    lower = math.ceil(A / x)
    upper = math.floor(B / x)

    num = upper - lower + 1
    return num

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

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

    C_num = compute_dividable_num(C, A, B)
    D_num = compute_dividable_num(D, A, B)

    CD = C / gcd(C, D) * D
    CD_num = compute_dividable_num(CD, A, B)

    C_or_D_num = C_num + D_num - CD_num

    num = (B - A + 1) - C_or_D_num

    print(num)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd
 
def number_calc(A,B,x):
    left = math.ceil(A/x)
    right = B//x
    res = max(right-left+1,0)
    return res
 
A,B,C,D = map(int,input().split())
 
ans = B-A+1
ans -=number_calc(A,B,C)
ans -=number_calc(A,B,D)
lcm = (C*D)//gcd(C,D)
ans +=number_calc(A,B,lcm)
 
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
import math
warareru = b-a
x = warareru//c
y = warareru//d
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

z = warareru//lcm(c,d)
print(warareru-(x+y-z))

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(float, input().split())
count = 0
for num in range(int(a), int(b), 1):
    if num % c != 0.0 and num % d != 0.0:
        count += 1
print (count)

Submission status: Wrong Answer

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

def gcd(x1, x2):
    x = x1 * x2
    r = x2 % x1
    while r != 0:
        x2 = x1
        x1 = r
        r = x2 % x1
    return x / x1

print((b-a) - (b-a)//c - (b-a)//d + c*d//gcd(c,d))

Submission status: Wrong Answer

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

def gcd(x1, x2):
    x = x1 * x2
    r = x2 % x1
    while r != 0:
        x2 = x1
        x1 = r
        r = x2 % x1
    return x / x1

print((b-a) - (b-a)/c - (b-a)/d + c*d/gcd(c,d))

Submission status: Wrong Answer

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

e = math.floor((c * d / fractions.gcd(c, d)))
 
 
f=math.floor((a-1)/c) 
g=math.floor(b/c) 
h=math.floor((a-1)/d) 
k=math.floor(b/d) 
l=math.floor((a-1)/e)
m=math.floor(b/e)
x=b-a+1
y=g-f
z=k-h
w=m-l
print(x-y-z+w)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = math.floor((c * d / gcd(c, d)))
 
 
f=math.floor((a-1)/c) 
g=math.floor(b/c) 
h=math.floor((a-1)/d) 
k=math.floor(b/d) 
l=math.floor((a-1)/e)
m=math.floor(b/e)
x=b-a+1
y=g-f
z=k-h
w=m-l
print(x-y-z+w)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = math.floor((c * d / gcd(c, d)))
 
 
f=math.floor((a-1)/c) 
g=math.floor(b/c) 
h=math.floor((a-1)/d) 
k=math.floor(b/d) 
l=math.floor((a-1)/e)
m=math.floor(b/e)
x=round(b-a+1)
y=round(g-f)
z=round(k-h)
w=round(m-l)
print(x-y-z+w)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = (c * d // gcd(c, d))
 
 
f=math.floor((a-1)/c) 
g=math.floor(b/c) 
h=math.floor((a-1)/d) 
k=math.floor(b/d) 
l=math.floor((a-1)/e)
m=math.floor(b/e)
x=round(b-a+1)
y=round(g-f)
z=round(k-h)
w=round(m-l)
print(x-y-z+w)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = (c * d / gcd(c, d))
 
 
f=math.floor((a-1)/c) 
g=math.floor(b/c) 
h=math.floor((a-1)/d) 
k=math.floor(b/d) 
l=math.floor((a-1)/e)
m=math.floor(b/e)
x=round(b-a+1)
y=round(g-f)
z=round(k-h)
w=round(m-l)
print(x-y-z+w)

Submission status: Wrong Answer

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

count = b - a
def baisuu(n):
    i1 = (a // n + bool(a == n))
    i2 = (b // n)
    return int(i2 - i1)

def gcd(x1, x2):
    x = x1 * x2
    r = x2 % x1
    while r != 0:
        x2 = x1
        x1 = r
        r = x2 % x1
    return x / x1

print(count - baisuu(c) - baisuu(d) + baisuu(gcd(c, d)))

Submission status: Wrong Answer

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

count = b - a
def baisuu(n):
    i1 = (a // n + bool(a % n))
    i2 = (b // n + bool(a % n))
    return int(i2 - i1)

def gcd(x1, x2):
    x = x1 * x2
    r = x2 % x1
    while r != 0:
        x2 = x1
        x1 = r
        r = x2 % x1
    return x / x1

print(count - baisuu(c) - baisuu(d) + baisuu(gcd(c, d)))

Submission status: Wrong Answer

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

count = b - a
def baisuu(n):
    i1 = (a // n)
    i2 = (b // n)
    return int(i2 - i1)

def gcd(x1, x2):
    x = x1 * x2
    r = x2 % x1
    while r != 0:
        x2 = x1
        x1 = r
        r = x2 % x1
    return x / x1

print(count - baisuu(c) - baisuu(d) + baisuu(gcd(c, d)))

Submission status: Wrong Answer

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

count = b - a
def baisuu(n):
    i1 = (a // n + bool(a % n))
    i2 = (b // n)
    return int(i2 - i1)

def gcd(x1, x2):
    x = x1 * x2
    r = x2 % x1
    while r != 0:
        x2 = x1
        x1 = r
        r = x2 % x1
    return x / x1

print(count - baisuu(c) - baisuu(d) + baisuu(gcd(c, d)))

Submission status: Wrong Answer

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

count = b - a
def baisuu(n):
    i1 = (a // n + bool(a % n))
    i2 = (b // n + bool(b % n))
    return int(i2 - i1)

def gcd(x1, x2):
    x = x1 * x2
    r = x2 % x1
    while r != 0:
        x2 = x1
        x1 = r
        r = x2 % x1
    return x / x1

print(count - baisuu(c) - baisuu(d) + baisuu(gcd(c, d)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

def solve(A, B, C, D):
    ans = B - A + 1
    div_c = (B // C) - ((A-1) // C)
    div_d = (B // D) - ((A-1) // D)
    lcm_cd = C*D // gcd(C, D)
    div_cd = (B // lcm_cd) - ((A-1) // lcm_cd)
    return ans - div_c - div_d + div_cd

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-1)//C
AD = (A-1)//D
A_lcm = (A-1)//lcm
A_num = AC+AD-A_lcm

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

print(int((B-A+1)-(B_num-A_num)))

Submission status: Wrong Answer

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

c_div=B//C
d_div=B//D
dc_div=B//((C*D)/gcd(C,D))

not_div1 = B-(d_div+c_div-dc_div)

A =A-1
c_div=A//C
d_div=A//D
dc_div=A//((C*D)/gcd(C,D))

not_div2 = A-(d_div+c_div-dc_div)

print(not_div1-not_div2)

Submission status: Wrong Answer

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

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

def f(X, C, D):
    return int(X // C) + int(X // D) - int(X // ((C * D ) / gcd(C, D)))

ans = int((B - A + 1)) - int(f(B, C, D)) + int(f(A - 1, C, D))

print(ans)

Submission status: Wrong Answer

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

count = b - a
def baisuu(n):
    x = n
    while True:
        if a <= x <= b:
            return x, n * (b // n)
        x += n
x1, x2 = baisuu(c)
x3, x4 = baisuu(d)
print(count - ((x2 - x1) // c) - ((x4 - x3) // d))
t1 = time.perf_counter()
print(t1 - t2)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
Input = input()
a, b, c, d = Input.split()
a, b, c, d = int(a), int(b), int(c), int(d)
delta_c = b//c - a//c
delta_d = b//d - a//d
def lcm(x, y):
    return (x * y) // gcd(x, y)
cd = lcm(c, d)
delta_cd = b//cd - a//cd
num_cd = delta_c + delta_d - delta_cd
print( b-a+1 - num_cd, end='')

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())
E=lcm(C,D)
P=int(B/C)
Q=int((A-1)/C)
R=int(B/D)
S=int((A-1)/D)
T=int(B/E)
U=int((A-1)/E)
V=int((P-Q)+(R-S)-(T-U))
print(B-A+1-V)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = b-(a-1) - (b//c - (a-1)//c) - (b//d - (a-1)//d) + (b//(c*d) - (a-1)//(c*d))

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import fractions
A, B, C, D = map(int, input().split())
g = C*D/fractions.gcd(C,D)
ans = 0
ans += B - math.floor(B/C) - math.floor(B/D) + math.floor(B/g)
ans -= A - 1 - math.floor((A-1)/C) - math.floor((A-1)/D) + math.floor((A-1)/g)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

input_line = input()
lines = input_line.split()
A = int(lines[0])
B = int(lines[1])
C = int(lines[2])
D = int(lines[3])
LCM = C * D / fractions.gcd(C,D)
#print('GCD',GCD)
num = B - A + 1
#print('num',num)
c_dec = int(B / C)
c_dec -= int(A / C)
#print('c_dec',c_dec)
d_dec = int(B / D)
d_dec -= int(A / D)
#print('d_dec',d_dec)
if LCM == C or LCM == D:
	lcm_dec = 0
else:
	lcm_dec = int(B / LCM)
	lcm_dec -= int(A / LCM)
print(num - c_dec - d_dec + lcm_dec)

Submission status: Wrong Answer

Solution code:
import math
import fractions
A, B, C, D = map(int, input().split())
g = C*D/fractions.gcd(C,D)
ans = 0
ans += math.floor(B/C) + math.floor(B/D) - math.floor(B/g)
ans -= math.floor((A-1)/C) + math.floor((A-1)/D) - math.floor((A-1)/g)
print(B-A+1-ans)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

a = A // C + A // D - A // lcm
b = B // C + B // D - B // lcm

print(B - b -(A - a))

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = (c * d / gcd(c, d))
 
 
f=math.ceil(a/c) 
g=math.floor(b/c) 
h=math.ceil(a/d) 
k=math.floor(b/d) 
l=math.ceil(a/e)
m=math.floor(b/e)
x=round(b-a+1)
y=round(g-f+1)
z=round(k-h+1)
w=round(m-l+1)
print(x-y-z+w)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

a = A // C + A // D - A // lcm
b = B // C + B // D - B // lcm

print(b - a)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = (c * d / gcd(c, d))
 
 
f=math.floor(a/c) 
g=math.floor(b/c) 
h=math.floor(a/d) 
k=math.floor(b/d) 
l=math.floor(a/e)
m=math.floor(b/e)
x=round(b-a+1)
y=round(g-f)
z=round(k-h)
w=round(m-l)
print(x-y-z+w)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = (c * d / gcd(c, d))
 
 
f=math.floor(a/c) 
g=math.floor(b/c) 
h=math.floor(a/d) 
k=math.floor(b/d) 
l=math.floor(a/e)
m=math.floor(b/e)
x=round(b-a+1)
y=round(g-f)
z=round(k-h)
w=round(m-l)
print(round(x-y-z+w))