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:
from fractions import gcd
import math
a,b,c,d = map(int,input().split())

an1 = math.floor(b/c)
an2 = math.floor((a-1)/c)
an3 = math.floor(b/d)
an4 = math.floor((a-1)/d) 
gcd = c * d / gcd(c, d)
an5 = math.floor(b/gcd)
an6 = math.floor((a-1)/gcd)
an = an1-an2 + an3-an4 -(an5-an6)
print((b-a+1)-an)

Submission status: Wrong Answer

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

def euc(a,b):
    x = a*b
    if(a<b):
        t = b
        b = a
        a = t
    
    r = a%b
    while(r!=0):
        a = b
        b = r
        r = a%b
    
    return int(x/b)

w = euc(C,D)
    
nc = math.floor(B/C)-math.floor((A-1)/C)
nd = math.floor(B/D)-math.floor((A-1)/D)
ncd = math.floor(B/w)-math.floor((A-1)/w)

nb = B - math.floor(B/C) - math.floor(B/D) + math.floor(B/w)
na = (A-1) - math.floor((A-1)/C) - math.floor((A-1)/D) + math.floor((A-1)/w)

n = nc + nd - ncd

print(B-A+1-n)

Submission status: Wrong Answer

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

if c == 1 or d == 1:
    print(0)
elif a == b:
    if a%c == 0 or a%d == 0:
        print(0)
    else:
        print(1)
else:
    an1 = math.floor(b/c)
    an2 = math.floor((a-1)/c)
    an3 = math.floor(b/d)
    an4 = math.floor((a-1)/d) 
    gcd = c * d / gcd(c, d)
    an5 = math.floor(b/gcd)
    an6 = math.floor((a-1)/gcd)
    an = an1-an2 + an3-an4 -(an5-an6)
    print((b-a+1)-an)

Submission status: Wrong Answer

Solution code:
import math

temp = input().split(" ")
min = int(temp[0])
max = int(temp[1])
divisor1 = int(temp[2])
divisor2 = int(temp[3])
divisors = [divisor1,divisor2] if divisor1 > divisor2 else [divisor2, divisor1]

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

gcdDivisors = gcd(divisors[0], divisors[1]);
lcmDivisors = int(divisor1 * divisor2 / gcdDivisors)

divNum1 = math.floor(max / divisor1) - math.ceil(min / divisor1) + 1;
divNum2 = math.floor(max / divisor2) - math.ceil(min / divisor2) + 1;
divNumLcm = math.floor(max / lcmDivisors) - math.ceil(min / lcmDivisors) + 1;
divNumTotal = divNum1 + divNum2 - divNumLcm;
ans = max - min + 1 - divNumTotal

print(ans)

Submission status: Wrong Answer

Solution code:
# 最初に入れておくとinputが早くなる
import sys
from fractions import gcd
input = sys.stdin.readline

a, b, c, d = map(int, input().split())
# warikireru = set()
# for i in range(b//c+1):
#    for j in range(b // d+1):
#        k = c ** i * d ** j
#        if(a <= k <= b):
#            warikireru.add(k)
# print(warikireru)
# print(b-a+1-len(warikireru))

k = c * d / gcd(c, d)
a -= 1
print(b-a+2-b//c+a//c-b//d+b//k+a//d-a//k)

Submission status: Wrong Answer

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

s=B-A+1-(((B//C) - (A//C) +1)+((B//D) - (A//D) +1)-(B//(C*D)))
print(s)

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())
if A%C==0 and B%C==0:
    C_div = (B-A+1)//C + 1
else:
    C_div = (B-A+1)//C
if B%D==0 and B%D==0:
    D_div = (B-A+1)//D + 1
else:
    D_div = (B-A+1)//D
if A%(lcm(C,D)) == 0 and B%(lcm(C,D)) == 0:
    CD_div = (B-A+1)//lcm(C,D) + 1
else:
    CD_div = (B-A+1)//lcm(C,D)
if C==1 or D==1:
    print(0)
else:
    print((B-A+1) - C_div -D_div + CD_div)

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)

CD=lcm(C, D)
 
def xc(x,C=C,D=D,CD=CD):
    return(-x//C -x//D + x//(CD))
  
print(B-A+1+xc(A)+xc(B))

Submission status: Wrong Answer

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

#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-1) / CD)

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

print(calc)

Submission status: Wrong Answer

Solution code:
# 最初に入れておくとinputが早くなる
import sys
from fractions import gcd
input = sys.stdin.readline

a, b, c, d = map(int, input().split())
a -= 1
# warikireru = set()
# for i in range(b//c+1):
#    for j in range(b // d+1):
#        k = c ** i * d ** j
#        if(a <= k <= b):
#            warikireru.add(k)
# print(warikireru)
# print(b-a+1-len(warikireru))

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

print(b-a-b//c+a//c-b//d+b//k+a//d-a//k)

# 4,6,8 3
# 9 1
# 6

# 12,18,24,30,36 5
# 16,24,32,40 4
# 31

Submission status: Wrong Answer

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

s = input().split(" ");
a = int(s[0]);
b = int(s[1]);
c = int(s[2]);
d = int(s[3]);
if a % c == 0 :
	min_c = int(a/c) - 1;
else :
	min_c = int(a/c);
if a % d == 0 :
	min_d = int(a/d) - 1;
else :
	min_d = int(a/d);
if a % lcm(c, d) == 0 :
	min_cd = int(a/lcm(c, d)) - 1;
else :
	min_cd = int(a/lcm(c, d));
num_c = int(b/c) - min_c;
num_d = int(b/d) - min_d; 
num_cd = int(b/lcm(c, d)) - min_cd;
print(b - a + 1 -(num_c + num_d - num_cd))

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())
CD = lcm(C, D)

c_first = 0
c_last = 0
d_first = 0
d_last = 0
cd_first = 0
cd_last = 0

c_first = (A-1) // C
c_last = B // C
d_first = (A-1) // D
d_last = B // D
cd_first = (A-1) // CD
cd_last = B // CD

c_count = 0
d_count = 0
cd_count = 0
if c_last != 0:
  c_count = c_last - c_first
if d_last != 0:
  d_count = d_last - d_first
if cd_last != 0:
  cd_count = cd_last - cd_first
    
print(c_first, c_last, d_first, d_last, cd_first, cd_last)
print(c_count, d_count, cd_count)
print(B - A + 1 - (c_count + d_count - cd_count))

Submission status: Wrong Answer

Solution code:
def saidaikouyaku(a, b):
    if b > a:
        a, b = b, a

    while b != 0:
        a, b=b,a%b
    return a

A, B, C, D = map(int, input().split())
hani = B - A + 1
Cnum = int(B / C) - int((A - 1) / C)
Dnum = int(B / D) - int((A - 1) / D)
saisyoukoubai = int(C * D / saidaikouyaku(C, D))
koubainum = int(B / saisyoukoubai) - int((A - 1) / saisyoukoubai)
#print(hani)
#print(Cnum, Dnum, koubainum)
print(hani - Cnum - Dnum + koubainum)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 22 21:34:54 2019

@author: owner
"""
# import math
# import fractions
import numpy as np

# def gcd_strategy():
#     return math.gcd if hasattr(math, "gcd") else fractions.gcd
# 
# gcd = gcd_strategy()

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

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

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

n_C = np.int(np.floor(B/C) - np.floor((A-1)/C))
n_D = np.int(np.floor(B/D) - np.floor((A-1)/D))

n_CD = np.int(np.floor(B/CD) - np.floor((A-1)/CD))

print('{}'.format(B-A+1-(n_C+n_D-n_CD)))

Submission status: Wrong Answer

Solution code:
import sys
import math
from fractions import gcd
inputs = sys.stdin.readlines()
a, b, c, d = [int(x) for x in inputs[0].split(' ')]
e = c * d // gcd(c, d) # lcm(c, d)

i = a + c - a % c
if i > b:
    i = b+1
c_ = math.ceil((b+1 - i) / c)

i = a + d - a % d
if i > b:
    i = b+1
d_ = math.ceil((b+1 - i) / d)
    
i = a + e - a % e
if i > b:
    i = b+1
e_ = math.ceil((b+1 - i) / e)

print(b+1 - a - c_ - d_ + e_)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int,input().split())
ans = b - a + 1#ok
a -= 1#ok

g = gcd(c,d)
temp = c*d/g
cc = -(a//c) + (b//c)
dd = -(a//d) + (b//d)
cd = -(a//temp) + (b//temp)

print(ans - cc - dd + cd)

Submission status: Wrong Answer

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


a1, b, c, d = map(float, input().split())
a = a1 - 1
Sa = a - a//c - a//d + a//(c*d//gcd(c, d))
Sb = b - b//c - b//d + b//(c*d//gcd(c, d))
print(int(Sb - Sa))

Submission status: Wrong Answer

Solution code:
import fractions

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

kobai = c * d / fractions.gcd(c, d)

bc = b / c
bd = b / d
b_kobai = b / kobai

b_num = b - bc - bc + b_kobai

ac = (a - 1) / c
ad = (a - 1) / d
a_kobai = (a - 1) / kobai

a_num = a - 1 - ac - ac + a_kobai

print(b_num - a_num)

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)


firstC = int((A-1)/C)
firstD = int((A-1)/D)
firstCD = int((A-1)/lcm(C,D))

# if A%lcm(C,D) ==0 and firstCD > 0:
#     firstCD -= 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:
a, b, c, d = map(int, input().split())

import fractions
import math

e = c*d//fractions.gcd(c,d)
x = b - b//c - b//d - b//e
y = (a-1) - (a-1)//c - (a-1)//d - (a-1)//e

print(x-y)

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())
if A%C==0 and B%C==0:
    C_div = (B-A+1)//C + 1
else:
    C_div = (B-A+1)//C
if B%D==0 and B%D==0:
    D_div = (B-A+1)//D + 1
else:
    D_div = (B-A+1)//D
if A%(lcm(C,D)) == 0 and B%(lcm(C,D)) == 0:
    CD_div = (B-A+1)//lcm(C,D) + 1
else:
    CD_div = (B-A+1)//lcm(C,D)
print((B-A+1) - C_div -D_div + CD_div)

Submission status: Wrong Answer

Solution code:
import fractions

A, B, C, D = map(int, input().split())
A -= 1
tmp = fractions.gcd(C, D)
lcd = (C * D) // tmp
acnt1 = A // C
acnt2 = A // D
acnt3 = B // C
acnt4 = B // D
acnt5 = A // lcd
acnt6 = B // lcd
ans = B - A
atmp = acnt3 + acnt4 - acnt5 + acnt6 - acnt1 - acnt2
ans -= atmp
print(ans)

Submission status: Wrong Answer

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

def gcd(a, b):
    if b == 0:
        return a
    else:
        while b:
            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-1) / c)
d2 = int(b / d) - int((a-1) / d)
e2 = int(b / (c*d/gcd(c,d))) - int((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
import fractions

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

# B以下の数でXの倍数の個数
def countX(X) :
    return X // B

Z = int(C * D / fractions.gcd(C,D))

ans = B - A + 1 - countX(C) - countX(D) + countX(Z)

Submission status: Wrong Answer

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

cnt = 0
s = b - a + 1
cd = (c*d) // gcd(c,d)

m1 = int((a-1) / c)
m2 = int(b / c)
cnt += (m2-m1)
#print(cnt)

m1 = int((a-1) / d)
m2 = int(b / d)
cnt += (m2-m1)
#print(cnt)

m1 = int((a-1) / cd)
m2 = int(b / cd)
cnt -= (m2-m1)
#print(cnt)

#print(cnt)
print(s - cnt)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())
cnt = 0
numc = b // c - (a - 1) // c
numd = b // d - (a - 1) // d
com = c * d / fractions.gcd(c,d)
numcd = b // com - (a - 1) // com
print(int(b - a + 1 - (numc + numd - numcd)))

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)


firstC = int((A-1)/C)
firstD = int((A-1)/D)
firstCD = int((A-1)/lcm(C,D))

# if A%lcm(C,D) ==0 and firstCD > 0:
#     firstCD -= 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((B-A+1)-NoP)

Submission status: Wrong Answer

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

C_ = int(B//C) - int(A//C)
D_ = int(B//D) - int(A//D)

E = int(C * D // int(fractions.gcd(C, D)))
E_ = int(B//E) - int(A//E)

ans = B - A + 1 - C_ - D_ + E_
print(ans)

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())
CD = lcm(C, D)

c_first = 0
c_last = 0
d_first = 0
d_last = 0
cd_first = 0
cd_last = 0

c_first = (A-1) // C
c_last = B // C
d_first = (A-1) // D
d_last = B // D
cd_first = (A-1) // CD
cd_last = B // CD

c_count = 0
d_count = 0
cd_count = 0
if c_last != 0:
  c_count = c_last - c_first + 1
if d_last != 0:
  d_count = d_last - d_first + 1
if cd_last != 0:
  cd_count = cd_last - cd_first + 1
    
#print(c_first, c_last, d_first, d_last, cd_first, cd_last)
#print(c_count, d_count, cd_count)
print(B - A + 1 - (c_count + d_count - cd_count))

Submission status: Wrong Answer

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


wad= int(a[1]/a[3])-int((a[0]-1)/a[3])

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


print(n-wac-wad+cd)

Submission status: Wrong Answer

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

if c == 1 or d == 1:
    print(0)
elif a == b:
    if a%c == 0 or a%d == 0:
        print(0)
    else:
        print(1)
else:
    an1 = math.floor(b/c)
    an2 = math.floor((a-1)/c)
    an3 = math.floor(b/d)
    an4 = math.floor((a-1)/d) 
    gcd = round(c * d / gcd(c, d))
    an5 = math.floor(b/gcd)
    an6 = math.floor((a-1)/gcd)
    an = an1-an2 + an3-an4 -(an5-an6)
    print((b-a+1)-an)

Submission status: Wrong Answer

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

def gcd(a, b):
    if b == 0:
        return 0
    else:
        while b:
            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-1) / c)
d2 = int(b / d) - int((a-1) / d)
e2 = int(b / (c*d/gcd(c,d))) - int((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:
from math import ceil,floor
from fractions import gcd

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

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

ans = B-A+1
ans -= B//C - ceil(A/C) + 1
ans -= B//D - ceil(A/D) + 1
ans += B//lcm(C,D) - ceil(A/lcm(C,D)) + 1

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int,input().split())
ans = b - a + 1#ok
a -= 1#ok

g = gcd(c,d)
temp = c*d/g
cc = -int(a/c) + int(b/c)
dd = -int(a/d) + int(b/d)
cd = -int(a/temp) + int(b / temp)

print(ans - cc - dd + cd)

Submission status: Wrong Answer

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

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

a, b, c, d = map(int, input().split())
count = 0
lower1 = int(a/c)
lower2 = int(a/d)
lower3 = int(a/lcm(c,d))
higher1 = b//c
higher2 = b//d
higher3 = b//lcm(c,d)

count = higher1 - lower1 + higher2 - lower2 - higher3 - lower3

print(b - a + 1 - count)

Submission status: Wrong Answer

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

E = C*D / gcd(C,D)
x = (A-1) // C
y = (A-1) // D
z = (A-1) // E

xx = B // C
yy = B // D
zz = B // E
xxx = xx-x
yyy = yy-y
zzz = zz-z
tmp = xx-x + yy-y - (zz-z)
print(int(B-A+1 - xxx - yyy + zzz))

Submission status: Wrong Answer

Solution code:
import math

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

under_a = a -1

b_mul = b - (b//c)-(b//d)+(b//(c*d))
under_a_mul = under_a - (under_a//c)-(under_a//d)+(under_a//(c*d))

print(b_mul-under_a_mul)

Submission status: Wrong Answer

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

if c == 1 or d == 1:
    print(0)
elif a == b:
    if a%c == 0 or a%d == 0:
        print(0)
    else:
        print(1)
else:
    if c < d:
        an1 = math.floor(b/c)
        an2 = math.floor((a-1)/c)
        an3 = math.floor(b/d)
        an4 = math.floor((a-1)/d) 
        gcd = round(c * d / gcd(c, d))
        an5 = math.floor(b/gcd)
        an6 = math.floor((a-1)/gcd)
        an = an1-an2 + an3-an4 -(an5-an6)
        print((b-a+1)-an)
   
        print((b-a+1)-an)

Submission status: Wrong Answer

Solution code:
def floor(a, b):
  return int((a - a%b)/b)
def gcd(a, b):
  while b != 0:
      a, b = b, a % b
  return a
def lcm(a, b):
  return floor((a * b), gcd(a, b))
input = list(map(int, input().split(' ')))
total_count = input[1] + 1 - input[0]
div_c = floor(input[1], input[2]) - floor(input[0] -1, input[2])
div_d = floor(input[1], input[3]) - floor(input[0] -1, input[3])
div_cd = floor(input[1], lcm(input[2], input[3])) - floor(input[0] -1, lcm(input[2], input[3]))
print(total_count - (div_c + div_d - div_cd))

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

# B以下の数でXの倍数の個数
def countX(X) :
    return X // B

Z = int(C * D / fractions.gcd(C,D))

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

Submission status: Wrong Answer

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

C_ = int(B/C) - int(A/C)
D_ = int(B/D) - int(A/D)

E = int(C * D // int(fractions.gcd(C, D)))
E_ = int(B/E) - int(A/E)

ans = B - A + 1 - C_ - D_ + E_
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor
from fractions import gcd

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

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

ans = B-A+1
ans -= (B//C - ceil(A/C) + 1)
ans -= (B//D - ceil(A/D) + 1)
ans += (B//lcm(C,D) - ceil(A/lcm(C,D)) + 1)

print(ans)

Submission status: Wrong Answer

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

def euc(a,b):
    x = a*b
    if(a<b):
        t = b
        b = a
        a = t
    
    r = a%b
    while(r!=0):
        a = b
        b = r
        r = a%b
    
    return int(x/b)

w = euc(C,D)
    
nc = int(B/C)-int((A-1)/C)
nd = int(B/D)-int((A-1)/D)
ncd = int(B/w)-int((A-1)/w)

nb = B -(int(B/C) + int(B/D) - int(B/w))
na = (A-1) -(int((A-1)/C) + int((A-1)/D) - int((A-1)/w))

n = nc + nd - ncd

print(nb-na)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

# B以下の数でXの倍数の個数
def countX(X) :
    return X // B

Z = int(C * D / fractions.gcd(C,D))

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

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())
if A%C==0 or B%C==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%(lcm(C,D)) == 0 or B%(lcm(C,D)) == 0:
    CD_div = (B-A+1)//lcm(C,D) + 1
else:
    CD_div = (B-A+1)//lcm(C,D)
print((B-A+1) - C_div -D_div + CD_div)

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-1)/C)
firstD = int((A-1)/D)
firstCD = int((A-1)/lcm(C,D))


# if A%lcm(C,D) ==0 and firstCD > 0:
#     firstCD -= 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:
from fractions import gcd
 
def main():
    a,b,c,d = map(int,input().split(" "))
    n = b - a + 1
    cd = int(c * d / gcd(c, d))
    cdiv = int(b/c) - int((a-1)/c)
    ddiv = int(b/d) - int((a-1)/d)
    cddiv = int(b/cd)  - int((a-1)/cd)
    print(n - cdiv -ddiv + cddiv)
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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 = [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-1) / c)
d2 = int(b / d) - int((a-1) / d)
e2 = int(b / (c*d/gcd(c,d))) - int((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:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


def count(n):
    return b // n - a // n


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

print(b - a + 1 - (count(c) + count(d) - count(lcm(c, d))))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split())
import fractions
 
def lcm(x,y):
  return (x * y) // fractions.gcd(x, y)

A = (a-1) // c + (a-1) // d - (a-1) // lcm(c,d)
B = b // c + b // d - b // lcm(c,d)
print(b-a+1-A+B)

Submission status: Wrong Answer

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


wad= int(a[1]/a[3])-int((a[0]-1)/a[3])

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


print(n-wac-wad+cd)

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())
A -= 1
E = lcm(C, D)
X = B//E - A//E
cc = B//C - A//C
dd = B//D - A//D
if max(C,D)%min(C,D) == 0:
    X += min(cc,dd)
print(B - A - cc - dd + X)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
import fractions
import math
nc=math.floor(b/c)-math.ceil((a-1)/c)
nd=math.floor(b/d)-math.ceil((a-1)/d)
min=c*d//fractions.gcd(c,d)
ncd=math.floor(b/min)-math.ceil((a-1)/min)
print(b-a+1-(nc+nd-ncd))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

np = (B - A + 1) + (-(B - A) // C)
nq = (B - A + 1) + (-(B - A) // D)


def coprime(a, b):
    return gcd(a, b) == 1


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


if coprime(C, D) == True:
    npq = (B - A + 1) + (-(B - A) // (C * D))
    print(np + nq - npq)
else:
    npq_ = (B - A + 1) + (-(B - A) // lcm(C, D))
    print(np + nq - npq_ - 1)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a, b):
	return int(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:
a,b,c,d=map(int,input().split())
import fractions
import math
nc=math.floor(b/c)-math.ceil((a-1)/c)+1
nd=math.floor(b/d)-math.ceil((a-1)/d)+1
min=c*d//fractions.gcd(c,d)
ncd=math.floor(b/min)-math.ceil((a-1)/min)+1
print(b-a+1-(nc+nd-ncd))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    a, b, c, d = MAP()
    g=gcd(c,d)
    l=int(c*d/g)
    a -= 1

    kukan1 = b - int(b / c) - int(b / d) + int(b / l)
    kukan2 = a - int(a / c) - int(a / d) + int(a / l)

    print(kukan1 - kukan2)


if __name__ == '__main__':
    main()

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-1/C)

firstD = int(A-1/D)


firstCD = int(A-1/lcm(C,D))


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)-NoP)

Submission status: Wrong Answer

Solution code:

import fractions
import math

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

U = B - A + 1

nA = ( math.floor(B / C) ) - (math.ceil(A / C)) +1

nB = ( math.floor(B / D) ) - (math.ceil(A / D)) +1

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

saisyoukoubaisuu = int(saisyoukoubaisuu)

nAB =  (math.floor(B/saisyoukoubaisuu)) - (math.ceil(A/saisyoukoubaisuu)) + 1

print( U -(nA + nB - nAB) )

Submission status: Wrong Answer

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

a,b,c,d = map(int,input().split())
t = 0
l = b-a+1

c_count = (b // c) - ((a-1) // c)

d_count = (b // d) - ((a-1) // d)

lc = gcd(c,d)
lc_count = (b // lc) - ((a-1) // lc)

print(l-c_count-d_count+lc_count)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions

input=stdin.readline().rstrip().split()
A=int(input[0])
B=int(input[1])
C=int(input[2])
D=int(input[3])
if C!=D:
    output=0
    Cmax=int(B/C)
    Cmin=int((A-1)/C)
    Dmax=int(B/D)
    Dmin=int((A-1)/D)
    CD=C*D//fractions.gcd(C,D)
    CDmax=int(B/CD)
    CDmin=int((A-1)/CD)
    output=(B-A+1)-((Cmax-Cmin)+(Dmax-Dmin)-(CDmax-CDmin))
    #print(Cmax,Cmin,Dmax,Dmin,CDmax,CDmin)
    print(output)
else:
    output=0
    Cmax=int(B/C)
    Cmin=int((A-1)/C)
    output=(B-A+1)-(Cmax-Cmin)
    #print(Cmax,Cmin)
    print(output)

Submission status: Wrong Answer

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

x = (A-1) // C
xx = B // C
y = (A-1) // D
yy = B // D
E = C*D / gcd(C,D)
z = (A-1) // E
zz = B // E
tmp = xx-x + yy-y - (zz-z)
tmp = xx+yy-zz -x-y+z
print(int(B-A - tmp))