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 = map(int,input().split())
l = (c*d)//fractions.gcd(c,d)
print(fractions.gcd(c,d))
if fractions.gcd(c,d) == 1:
	l = 10**18+1
	num =((a//c)+(a//d))-(a//l)- (a//(c*d))
	num2 =((b//c)+(b//d))-(b//l)-(b//(c*d))
	print(b-a-(num2-num)+1)
else:
	num =((a//c)+(a//d))-(a//l)- (a//(c*d))
	num2 =((b//c)+(b//d))-(b//l)-(b//(c*d))-1
	print(b-a-(num2-num))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())
l = (c*d)//fractions.gcd(c,d)
if fractions.gcd(c,d) == 1:
	l = 10**18+1
	num =((a//c)+(a//d))-(a//l)- (a//(c*d))
	num2 =((b//c)+(b//d))-(b//l)-(b//(c*d))
	print(b-a-(num2-num))
else:
	num =((a//c)+(a//d))-(a//l)- (a//(c*d))
	num2 =((b//c)+(b//d))-(b//l)-(b//(c*d))-1
	print(b-a-(num2-num))

Submission status: Wrong Answer

Solution code:
import sys
import math

def input():
    return sys.stdin.readline().rstrip()


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

    A = A-1
    ans = B//C - A //C
    ans += B//D - A //D
    lcm = C*D /math.gcd(C,D)
    ans -= B//lcm - A//lcm

    print(B-A-int(ans))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

a,b,c,d = I()
x = lcm(c,d)

if a == b:
    if a % c != 0 and a % d != 0:
        print(1)
        sys.exit()
    else:
        print(0)
        sys.exit()

aa = a-1-(a-1)//x + (a-1)//c + (a-1)//d
bb = b-b//x + b//c + b//d
ans = bb-aa

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

a,b,c,d = I()
x = lcm(c,d)

if a == b:
    if a % c != 0 and a % d != 0:
        print(1)
        sys.exit()
    else:
        print(0)
        sys.exit()

aa = -(a-1)//x + (a-1)//c + (a-1)//d
bb = -b//x + b//c + b//d
ans = (b-a+1)-(bb-aa)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

a,b,c,d = I()
x = lcm(c,d)

aa = -(a-1)//x + (a-1)//c + (a-1)//d
bb = -b//x + b//c + b//d
ans = (b-a+1)-(bb-aa)

print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

a,b,c,d = I()
x = lcm(c,d)

aa = - ((a-1) // x) + ((a-1) // c) + ((a-1) // d)
bb = - b // x + b // c + b // d
ans = (b-a+1)-(bb-aa)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

a,b,c,d = I()
x = lcm(c,d)

aa = - (a-1) // x + (a-1) // c + (a-1) // d
bb = - b // x + b // c + b // d
ans = (b-a+1)-(bb-aa)

print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

ans_lt_b = b - (b // c + b // d - b // lcm_cd)
ans_lt_a = (a - 1) - (((a - 1) // c) + ((a - 1) // d) + ((a - 1) // lcm_cd))
print(ans_lt_b - ans_lt_a)

Submission status: Wrong Answer

Solution code:

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

ans_lt_b = b - (b // c + b // d - b // (c * d))
ans_lt_a = (a - 1) - (((a - 1) // c) + ((a - 1) // d) + ((a - 1) // (c * d)))
print(ans_lt_b - ans_lt_a)

Submission status: Wrong Answer

Solution code:
#入力:N,M(int:整数)
def input2():
	return map(int,input().split())
  
a,b,c,d=input2()
c_len=b//c #b以下のcの倍数の個数
d_len=b//d #b以下のdの倍数の個数
all_len=b//(c*d) #重複

ans=b-(c_len+d_len)+all_len

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

print(ans)

Submission status: Wrong Answer

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

a -= 1
a_b = c * d // math.gcd(c, d)
print(a_b)
ans_a = a - (a // c + a // d - a // a_b)
ans_b = b - (b // c + b // d - b // a_b)

print(int(ans_b-ans_a))

Submission status: Wrong Answer

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

a -= 1
a_b = c * d / math.gcd(c, d)
ans_a = a - (a // c + a // d - a // a_b)
ans_b = b - (b // c + b // d - b // a_b)

print(int(ans_b-ans_a))

Submission status: Wrong Answer

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

dC = math.floor(b/c)-math.floor((a-1)/c)
dD = math.floor(b/d) - math.floor((a-1)/d)
lcm = c*d // math.gcd(c,d)
dCD = math.floor(b/lcm) - math.floor((a-1)/lcm) 
print(b - a + 1 -(dC + dD - dCD))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

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

dif = b-a
div_c = dif//c
div_d = dif//d
div_cd = dif//(lcm)

ans = dif - (div_c + div_d) + div_cd
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math

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

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

num = b-a
c_1 = (b-a)//c
d_1 = (b-a)//d
cd_1 = (b-a)//(lcm)

ans = num - (c_1 + d_1) + cd_1
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math

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

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

num = b-a
c_1 = (b-a)//c
d_1 = (b-a)//d
cd_1 = (b-a)//(lcm)

ans = num - (c_1 + d_1) + cd_1
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math

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


lcm = a * b / math.gcd(a, b)

num = b-a
c_1 = (b-a)//c
d_1 = (b-a)//d
cd_1 = (b-a)//(lcm)

ans = num - (c_1 + d_1) + cd_1
print(ans)

Submission status: Wrong Answer

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

num = b-a
c_1 = (b-a)//c
d_1 = (b-a)//d
cd_1 = (b-a)//(c*d)

ans = num - (c_1 + d_1) + cd_1
print(ans)

Submission status: Wrong Answer

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

import sys

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

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

def main():
    input = sys.stdin.readline
    a, b, c, d = map(int, input().split())
    a_1 = a - 1
    lcm_cd = lcm(c,d)
    
    a_1_c_count = int(a_1 / c)
    a_1_d_count = int(a_1 / d)
    a_lcm_count = int(a_1 / lcm_cd)

    a_1_result = a_1 - (a_1_c_count + a_1_d_count - a_lcm_count)


    b_c_count = int(b / c)
    b_d_count = int(b / d)
    b_lcm_count = int(b / lcm_cd)

    b_result = (b) - (b_c_count + b_d_count - b_lcm_count)

    result = b_result - a_1_result

    print(result)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

tmp1=b//c + b//d - b//(c*d) #1~bまで調べたとき、割り切れる数の個数
tmp2=(a-1)//c + (a-1)//d - (a-1)//(c*d) #1~a-1まで調べたとき、割り切れる数の個数
tmp=tmp1-tmp2 #a~bまで調べたとき、割り切れる数の個数
ans=(b-a+1)-tmp

print(ans)

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

g = math.gcd(c, d)
l = lcm(c, d)

print(b-a+1 - (b//c - a//c + b//d - a//d -b//l + a//l))

Submission status: Wrong Answer

Solution code:
from math import floor, ceil, gcd

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

if a%c == 0: c_m_min = a
else: c_m_min = a + c - a%c
c_m_max = b - b%c
print(c_m_min, c_m_max)
c_cnt = (c_m_max - c_m_min)//c + 1
if c_m_min > b or c_m_max < a : c_cnt = 0

if a%d == 0: d_m_min = a
else: d_m_min = a + d - a%d
d_m_max = b - b%d
d_cnt = (d_m_max - d_m_min)//d + 1
if d_m_min > b or d_m_max < a : d_cnt = 0

cd = c*d//gcd(c,d)
if a%cd == 0: cd_m_min = a
else: cd_m_min = a + cd - a%cd
cd_m_max = b - b%cd
cd_cnt = (cd_m_max - cd_m_min)//cd + 1
if cd_m_min > b or cd_m_max < a : cd_cnt = 0


ans = b - a + 1 - c_cnt - d_cnt + cd_cnt
print(ans)

Submission status: Wrong Answer

Solution code:
from math import floor, ceil, gcd

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

c_m_min = ceil(a/c)*c
c_m_max = floor(b/c)*c
c_cnt = (c_m_max - c_m_min)//c + 1
if c_m_min > b or c_m_max < a : c_cnt = 0

d_m_min = ceil(a/d)*d
d_m_max = floor(b/d)*d
d_cnt = (d_m_max - d_m_min)//d + 1
if d_m_min > b or d_m_max < a : d_cnt = 0

cd = c*d//gcd(c,d)
cd_m_min = ceil(a/cd)*cd
cd_m_max = floor(b/cd)*cd
cd_cnt = (cd_m_max - cd_m_min)//cd + 1
if cd_m_min > b or cd_m_max < a : cd_cnt = 0


ans = b - a + 1 - c_cnt - d_cnt + cd_cnt
print(ans)

Submission status: Wrong Answer

Solution code:
from math import floor, ceil, gcd

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

c_m_min = ceil(a/c)*c
c_m_max = floor(b/c)*c
c_cnt = (c_m_max - c_m_min)//c + 1
if c_m_min > b or c_m_min < a : c_cnt = 0

d_m_min = ceil(a/d)*d
d_m_max = floor(b/d)*d
d_cnt = (d_m_max - d_m_min)//d + 1
if d_m_min > b or d_m_min < a : d_cnt = 0

cd = c*d//gcd(c,d)
cd_m_min = ceil(a/cd)*cd
cd_m_max = floor(b/cd)*cd
cd_cnt = (cd_m_max - cd_m_min)//cd + 1
if cd_m_min > b or cd_m_min < a : cd_cnt = 0


ans = b - a + 1 - c_cnt - d_cnt + cd_cnt
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd as gcd
a, b, c, d = map(int,input().split())
#cでわれるもの
s = gcd(c, d)
p = c / s * d 
divide_c = b // c - (a - 1) // c
divide_d = b // d - (a - 1) // d
divide_cd = b // p - (a - 1) // p
print(int(b - a + 1 - divide_c - divide_d + divide_cd))

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int,input().split())
#cでわれるもの
divide_c = b // c - (a - 1) // c
divide_d = b // d - (a - 1) // d
divide_cd = b // (c * d) - (a - 1) // (c * d)
print(b - a + 1 - divide_c - divide_d + divide_cd)

Submission status: Wrong Answer

Solution code:
from math import floor, ceil, gcd

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

c_m_min = ceil(a/c)*c
c_m_max = floor(b/c)*c
c_cnt = (c_m_max - c_m_min)//c + 1

d_m_min = ceil(a/d)*d
d_m_max = floor(b/d)*d
d_cnt = (d_m_max - d_m_min)//d + 1

cd = c*d//gcd(c,d)
cd_m_min = ceil(a/cd)*cd
cd_m_max = floor(b/cd)*cd
cd_cnt = (cd_m_max - cd_m_min)//cd + 1

ans = b - a +1 - c_cnt - d_cnt + cd_cnt
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce
from collections import deque
# from math import factorial
import itertools
import collections
import math
import sys
sys.setrecursionlimit(2000000)
A, B, C, D = list(map(int, input().split()))

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


# b以下での個数
cb = B//C
db = B//D
cdb = B//(lcm(C, D))
total_b = cb+db-cdb

# a以下での個数
A -= 1
ca = A//C
da = A//D
cda = A//(lcm(C, D))
total_a = ca+da-cda

# print(total_a)
# print(total_b)
t = int(B-A)
s = int(total_b-total_a)
print(t-s)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
import math
c_div = 0
d_div = 0
if a % c == 0:
    c_div = max(0, 1 + ((b - (b % c)) - a) // c )
else:
    c_div = max(0, 1 + ((b - (b % c)) - (a + (c - a % c))) // c )
if a % d == 0:
    d_div = max(0, 1 + ((b - (b % d)) - a) // d )
else:
    d_div = max(0, 1 + ((b - (b % d)) - (a + (d - a % d))) // d )
gcd_input = c * d // math.gcd(c, d)
c_d_div = max(0, 1 + ((b - (b % gcd_input)) - (a + (gcd_input - a % gcd_input))) // gcd_input )
print(b - a + 1 - d_div - c_div + c_d_div)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A,B,C,D = list(map(int,input().split()))
num_C_bai = ((B-(B%C) - (A-(A%C)+C)))//C + 1
num_D_bai = ((B-(B%D) - (A-(A%D)+D)))//D + 1
E = lcm(C,D)
num_E_bai = ((B-(B%E) - (A-(A%E)+E)))//E + 1
print(B + 1 - A - num_C_bai - num_D_bai + num_E_bai)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int,input().split())
lcm=c*d//math.gcd(c,d)
a1,a2,a3=int((a-1)/c),int((a-1)/d),int((a-1)/lcm)
b1,b2,b3=int(b/c),int(b/d),int(b/lcm)
ans=int(b-a+1-(b1+b2-b3-a1-a2+a3))
print(ans)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int,input().split())
lcm=c*d/math.gcd(c,d)
a1,a2,a3=int((a-1)/c),int((a-1)/d),int((a-1)/lcm)
b1,b2,b3=int(b/c),int(b/d),int(b/lcm)
ans=int(b-a+1-(b1+b2-b3-a1-a2+a3))
print(ans)

Submission status: Wrong Answer

Solution code:
a = input().split(" ")
A = int(a[0])
B = int(a[1])
C = int(a[2])
D = int(a[3])
cm = C // A
dm = D // A
cc = C // B
dc = D // B
countm = C * D // A
countc = C * D // B
print(cc + dc - cm - dm + countm - countc)

Submission status: Wrong Answer

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

def gcd(a,b):
    x=max(a,b)
    y=min(a,b)
    
    while True:
#         print(x,y)
        y_ = x % y
        if y_ == 0:
            return y
        x = y
        y = y_

def lcm(a,b):
    ans=Decimal(a*b)/Decimal(gcd(a,b))
    return ans.as_integer_ratio()[0]

CD=lcm(C,D)
len_all = B-A+1
len_c = (B+0.1)//C-(A-0.1)//C
len_d = (B+0.1)//D-(A-0.1)//D
len_c_and_d = (B+0.1)//CD-(A-0.1)//CD

ans=len_all-len_c-len_d+len_c_and_d 
print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def cnt(a, b, n):
  be = a//n
  if a%n:
    be+=1
  en = b//n
  return en-be+1

print(cnt(a, b, c)+cnt(a, b, d)-cnt(a, b, c*d))

Submission status: Wrong Answer

Solution code:
from math import gcd
def lcm(a, b):
    return a*b//gcd(a,b)

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

nC = (B-A)//C + 1
nD = (B-A)//D + 1
nCD = (B-A)//lcm(C,D) + 1

print((B-A+1)-(nC+nD-nCD))

Submission status: Wrong Answer

Solution code:
import math

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

n = b - a + 1
x = n // c
y = n // d
z = n // ((c * d) // math.gcd(c, d))

ans = n - (x + y - z) - 1
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math
a, b, c, d = map(int,input().split())

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

ans = b//c-(a-1)//c#cで
ans += b//d-(a-1)//d#dで
#print(ans)

ans -= b//e-(a-1)//e#両方で
print(max(int(b-a+1-ans),0))

Submission status: Wrong Answer

Solution code:
import math

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


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

CL=(A-1)//C
CH=B//C
DL=(A-1)//D
DH=B//D
ACD=A//lcm(C,D)
BCD=B//lcm(C,D)

#print(CL,CH,DL,DH,ACD,BCD)

ans=(B-A+1)-((CH-CL)+(DH-DL)-(BCD-ACD))
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

A,B,C,D=map(int,input().split())
BA=B-A
CD=lcm(C,D)
AC=A%C
AD=A%D
ACD=A%CD
ans=BA+1

ans-=max((BA-(C-AC)%C)//C,0)
ans-=max((BA-(D-AD)%D)//D,0)
ans+=max((BA-(CD-ACD)%CD)//CD,0)


if (BA-(C-AC)%C)>0:
    ans-=1

if (BA-(D-AD)%D)>0:
    ans-=1

if (BA-(CD-ACD)%CD)>0:
    ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math
a, b, c, d = map(int,input().split())

e = math.gcd(c,d)
e = c*d/e
ans = b//c-(a-1)//c+b//d-(a-1)//d
#print(ans)

ans -= b//e-(a-1)//e
print(int(b-a+1-ans))

Submission status: Wrong Answer

Solution code:
from math import *
a,b,c,d = map(int,input().split())
f =(c*d)//gcd(c,d)
r = f
rock = 2
compteur= b//f
div1 = ((b//c)-(a//c))
div2 = ((b//d)-(a//d))
if  a%c == 0 or a%d ==0:
  div1+=1
roger =(div1+div2)-compteur
mm = (b-a)+1
print(mm-roger)

Submission status: Wrong Answer

Solution code:
from math import *
a,b,c,d = map(int,input().split())
f =(c*d)//gcd(c,d)
r = f
rock = 2
compteur= b//f
div1 = ((b//c)-(a//c))
div2 = ((b//d)-(a//d))
if  a%c == 0:
  div1+=1
if a%d ==0:
  div2 +=1
roger =(div1+div2)-compteur
mm = (b-a)+1
print(mm-roger)

Submission status: Wrong Answer

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

bc = b//c
bd = b//d

import math
bcd = b//(c*d/math.gcd(c,d))

ac = (a-1)//c
ad = (a-1)//d
acd = (a-1)//(c*d/math.gcd(c,d))

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

print(ans)

Submission status: Wrong Answer

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

bc = b//c
bd = b//d

import math
bcd = b//(c*d/math.gcd(c,d))

ac = (a-1)//c
ad = (a-1)//d
acd = (a-1)//(c*d/math.gcd(c,d))

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

print(ans)

Submission status: Wrong Answer

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

bc = b//c
bd = b//d

import math
bcd = b//(c*d/math.gcd(c,d))

ac = (a-1)//c
ad = (a-1)//d
acd = (a-1)//(c*d/math.gcd(c,d))

ans = (b-(bc+bd-bcd))-((a-1)-(ac+ad-acd))

print(ans)

Submission status: Wrong Answer

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

bc = b//c
bd = b//d

import math
bcd = c*d//math.gcd(c,d)

ac = (a-1)//c
ad = (a-1)//d
acd = c*d//math.gcd(c,d)

ans = (b-(bc+bd-bcd))-((a-1)-(ac+ad-acd))

print(ans)

Submission status: Wrong Answer

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

bc = b//c
bd = b//d

import math
bcd = c*d/math.gcd(c,d)

ac = (a-1)//c
ad = (a-1)//d
acd = c*d//math.gcd(c,d)

ans = (b-(bc+bd-bcd))-((a-1)-(ac+ad-acd))

print(int(ans))

Submission status: Wrong Answer

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

bc = b//c
bd = b//d

import math
bcd = c*d/math.gcd(c,d)

ac = (a-1)//c
ad = (a-1)//d
acd = (a-1)//math.gcd(c,d)

ans = (b-(bc-bd+bcd))-(a-1-(ac-ad+acd))

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math

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

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

x = b//c-a//c 

x += b//d-a//d

x -= b//e-a//e 

if a%c == 0:
    x += 1
    
if a%d == 0:
    x += 1
    
if a%e == 0:
    x += 1
    
print(b-a-x+1)

Submission status: Wrong Answer

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

from fractions import*
upto_B=B-(B//C+B//D-B//(C*D//gcd(C,D)))
upto_A=A-1-((A-1)//C+(A-1)//D-(A-1)//(C*D//gcd(C,D)))

print(upto_B-upto_A*(A>2))

Submission status: Wrong Answer

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

from math import*
upto_B=B-(B//C+B//D-B//(C*D//gcd(C,D)))
upto_A=A-1-((A-1)//C+(A-1)//D-(A-1)//(C*D//gcd(C,D)))

print(upto_B-upto_A*(A>2))

Submission status: Wrong Answer

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

if c > d:
    c, d = d, c

q11 = (a-1)//c
q12 = (a-1)//d

q21 = b//c
q22 = b//d

if d%c != 0:
    q3 = (a-1)//(c*d)
    q4 = b//(c*d)
    print(b-(a-1) - (q21-q11) - (q22-q12) + (q4-q3))
else:
    print(b-(a-1) - (q21-q11))

Submission status: Wrong Answer

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

q11 = (a-1)//c
q12 = (a-1)//d

q21 = b//c
q22 = b//d

q3 = (a-1)//(c*d)
q4 = b//(c*d)

print(b-(a-1) - (q21-q11) - (q22-q12) + (q4-q3))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s1 = (a-1) // c
s2 = (a-1) // d
s3 = (a-1) // (c*d)
S = (a-1) - (s1 + s2 -s3)

l1 = b // c
l2 = b // d
l3 = b // (c*d)
L = b - (l1 + l2 - l3)

print(L-S)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int,input().split())
lcm_cd=(c*d)/(math.gcd(c,d))
c_times=b//c-(a-1)//c
d_times=b//d-(a-1)//d
cd_times=b//lcm_cd-(a-1)//lcm_cd
print(int(b-a+1-c_times-d_times+cd_times))

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int,input().split())
lcm_cd=c*d/math.gcd(c,d)
c_times=b//c-(a-1)//c
d_times=b//d-(a-1)//d
cd_times=b//lcm_cd-(a-1)//lcm_cd
print(int(b-a+1-c_times-d_times+cd_times))

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int,input().split())
lcm_cd=c*d/math.gcd(c,d)
c_times=b//c-(a-1)//c
d_times=b//d-(a-1)//d
cd_times=b//lcm_cd-(a-1)//lcm_cd
print(int(b-a+1-c_times-d_times+cd_times))

Submission status: Wrong Answer

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

c=(int((B-B%C)-(A-1+C-(A-1)%C))/C)+1
d=(int((B-B%D)-(A-1+D-(A-1)%D))/D)+1
lcm=C*D/math.gcd(C,D)
candd=((B-B%lcm)-(A-1+lcm-(A-1)%lcm))/lcm+1
print(int(B-A+1-c-d+candd))

Submission status: Wrong Answer

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

c=(int((B-B%C)-(A-1+C-(A-1)%C))/C+0.5)+1
d=(int((B-B%D)-(A-1+D-(A-1)%D))/D+0.5)+1
lcm=C*D/math.gcd(C,D)
candd=((B-B%lcm)-(A-1+lcm-(A-1)%lcm))/lcm+1
print(int(B-A+1-c-d+candd))

Submission status: Wrong Answer

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

c=((B-B%C)-(A-1+C-(A-1)%C))/C+1
d=((B-B%D)-(A-1+D-(A-1)%D))/D+1
lcm=C*D/math.gcd(C,D)
candd=((B-B%lcm)-(A-1+lcm-(A-1)%lcm))/lcm+1
print(int(B-A+1-c-d+candd))

Submission status: Wrong Answer

Solution code:
from math import gcd, ceil
a, b, c, d = map(int, input().split())
lcm = c * d // gcd(c, d)
ans = (b-a+1 - ceil((b-a+1)/c) - ceil((b-a+1)/d) + ceil((b-a+1)/lcm))
print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D = input().split()
A = int(A)
B = int(B)
C = int(C)
D = int(D)
from math import gcd
G = gcd(C,D)
L = D*C/G
#print(A,B,C,D)
temp1 = (B-A+1)
temp2 = (((B-B%C)-((C-A%C)%C+A))/C+1 + ((B-B%D)-((D-A%D)%D+A))/D+1)
temp3 = ((B-B%(L)) - ((L-A%(L))%(L)+A))/(L)+1
temp4 = ((B-B%C)-((C-A%C)%C+A))/C+1
temp5= ((B-B%D)-((D-A%D)%D+A))/D+1
#print(temp4, temp5)
#print(temp1, temp2, temp3)
print(int(temp1-temp2+temp3))

Submission status: Wrong Answer

Solution code:
A,B,C,D = input().split()
A = int(A)
B = int(B)
C = int(C)
D = int(D)
#print(A,B,C,D)
temp1 = (B-A+1)
temp2 = (((B-B%C)-((C-A%C)%C+A))/C+1 + ((B-B%D)-((D-A%D)%D+A))/D+1)
temp3 = ((B-B%(C*D)) - ((D*C-A%(D*C))%(D*C)+A))/(D*C)+1
#print(temp1, temp2, temp3)
print(int(temp1-temp2+temp3))

Submission status: Wrong Answer

Solution code:
from math import gcd
a, b, c, d = map(int,input().split())
c_explicit = b // c - (a - 1)// c 
d_explicit = b // d - (a - 1)// d
e = gcd(c, d)
gcl = c * d / e
e_explicit = b // gcl - (a - 1)// gcl
g = b - a + 1 - c_explicit - d_explicit + e_explicit
print(g)

Submission status: Wrong Answer

Solution code:
from math import gcd
a, b, c, d = map(int,input().split())
if a % c ==0:
    c_explicit = b // c - a // c + 1
else:
    c_explicit = b // c - a // c 
if a % d ==0:
    d_explicit = b // d - a // d + 1
else:
    d_explicit = b // d - a // d 
e = gcd(c, d)
gcl = (c / e) * (d / e) * e
if a % gcl ==0:
    e_explicit = b // gcl - a // gcl + 1
else:
    e_explicit = b // gcl - a // gcl 
g = b - a + 1 - c_explicit - d_explicit + e_explicit
print(int(g))

Submission status: Wrong Answer

Solution code:
from math import gcd
from decimal import Decimal as dec 
a, b, c, d = map(dec,input().split())
if a % c ==0:
    c_explicit = b // c - a // c + 1
else:
    c_explicit = b // c - a // c 
if a % d ==0:
    d_explicit = b // d - a // d + 1
else:
    d_explicit = b // d - a // d 
e = gcd(int(c), int(d))
e = dec(e)
gcl = (c / e) * (d / e) * e
if a % gcl ==0:
    e_explicit = b // gcl - a // gcl + 1
else:
    e_explicit = b // gcl - a // gcl 
print(c_explicit, d_explicit, e_explicit, gcl)
g = b - a + 1 - c_explicit - d_explicit + e_explicit
print(g)

Submission status: Wrong Answer

Solution code:
from math import gcd
a, b, c, d = map(int,input().split())
if a % c ==0:
    c_explicit = b // c - a // c + 1
else:
    c_explicit = b // c - a // c 
if a % d ==0:
    d_explicit = b // d - a // d + 1
else:
    d_explicit = b // d - a // d 
e = gcd(c, d)
gcl = (c / e) * (d / e) * e
if a % gcl ==0:
    e_explicit = b // gcl - a // gcl + 1
else:
    e_explicit = b // gcl - a // gcl 
print(c_explicit, d_explicit, e_explicit, gcl)
g = b - a + 1 - c_explicit - d_explicit + e_explicit
print(int(g))

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())
e=lcm(c,d)

n=(b//c)-((a-1)//c)
m=(b//d)-((a-1)//d)
o=b//e



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

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())
e=lcm(c,d)

n=(b//c)-((a-1)//c)
m=(b//d)-((a-1)//d)
o=(b//e)-(a//e)



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

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())
e=lcm(c,d)

n=(b//c)-(a//c)
m=(b//d)-(a//d)
o=(b//e)-(a//e)

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

Submission status: Wrong Answer

Solution code:
import math

def lec(a, b):
    # aとbの最小公倍数
    return a * b // math.gcd(a, b)

def cal_num(a, b, x):
    # a ~ bの数値の中にxの倍数が入っている数
    if b >= x:
        x_cum = math.floor(b / x) - math.floor((a-1) / x)
    else:
        x_cum = 0
    return x_cum

if __name__ == "__main__":
    A, B, C, D = map(int, input().split())

    CD = lec(C, D)
    C_num = cal_num(A, B, C)
    D_num = cal_num(A, B, D)
    CD_num = cal_num(A, B, CD)
    answer = B - A + 1 - C_num - D_num + CD_num

    print(answer)

Submission status: Wrong Answer

Solution code:
import math

def lec(a, b):
    # aとbの最小公倍数
    return a * b // math.gcd(a, b)

def cal_num(a, b, x):
    # a ~ bの数値の中にxの倍数が入っている数
    if b >= x:
        x_cum = math.floor(b / x) - math.ceil(a / x) + 1
    else:
        x_cum = 0
    return x_cum

if __name__ == "__main__":
    A, B, C, D = map(int, input().split())

    CD = lec(C, D)
    C_num = cal_num(A, B, C)
    D_num = cal_num(A, B, D)
    CD_num = cal_num(A, B, CD)
    answer = B - A + 1 - C_num - D_num + CD_num

    print(answer)

Submission status: Wrong Answer

Solution code:
import math

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

def lec(a, b):
    # aとbの最小公倍数
    return a * b // math.gcd(a, b)

CD = int(lec(C, D))
C_num = math.floor(B / C) - math.ceil(A / C) + 1
D_num = math.floor(B / D) - math.ceil(A / D) + 1
CD_num = math.floor(B / CD) - math.ceil(A / CD) + 1

answer = B - A + 1 - C_num - D_num + CD_num

print(answer)

Submission status: Wrong Answer

Solution code:
import math

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

def lec(a, b):
    # aとbの最小公倍数
    return a * b // math.gcd(a, b)

CD = lec(C, D)
C_num = math.floor(B / C) - math.ceil(A / C) + 1
D_num = math.floor(B / D) - math.ceil(A / D) + 1
CD_num = math.floor(B / CD) - math.ceil(A / CD) + 1

answer = B - A + 1 - C_num - D_num + CD_num

print(answer)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d=map(int,input().split())
ans=0
g=gcd(c, d)
n=int(c*d/g)
if b-a<=3*n:
    for i in range(a,b+1):
        if i%c!=0 and i%d!=0:
            ans=ans+1
else:
    a1=a//n
    b1=b//n
    for i in range(a,n*(a1+2)):
        if i%c!=0 and i%d!=0:
            ans=ans+1
    for i in range(n*b1,b+1):
        if i%c!=0 and i%d!=0:
            ans=ans+1
    num=0
    for i in range(1,n+1):
        if i%c!=0 and i%d!=0:
            num=num+1
    m=b1-a1-1
    ans=ans+num*m
print(ans)

Submission status: Wrong Answer

Solution code:
def div(n, m):
  return n // m
a, b, c, d = map(int, input().split())
ans = 0
a -= 1
e = b - div(b, c) - div(b, d)
f = a - div(a, c) - div(a, d)
x = c * d
if c < d:
  tmp = c
  c = d
  d = tmp
r = c % d
while r != 0:
  c = d
  d = r
  r = c % d
lcm = x/d
e += div(b, lcm)
f += div(a, lcm)
ans = int(e - f)
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
ac = (a-1)//c
bc = b//c
ad = (a-1)//d
bd = b//d
ans1 = bc-ac
ans2 = bd-ad
print((b-a)-max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())
num = b-a+1
ac = int(a//c)
ad = int(a//d)
bc = int(b//c)
bd = int(b//d)
e = c*d//(fractions.gcd(c,d))
a = int(a//e)
b = int(b//e)
c = bc-ac
d = bd-ad
e = b-a
print(num-(c+d-e))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())
num = b-a+1
ac = int((a-1)//c)
ad = int((a-1)//d)
bc = int(b//c)
bd = int(b//d)
e = c*d//(fractions.gcd(c,d))
a = int(a//e)
b = int(b//e)
c = bc-ac
d = bd-ad
e = b-a
print(num-(c+d-e))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())
num = b-a+1
ac = int((a-1)/c)
ad = int((a-1)/d)
bc = int(b/c)
bd = int(b/d)
e = c*d//(fractions.gcd(c,d))
a = int(a/e)
b = int(b/e)
c = bc-ac
d = bd-ad
e = b-a
print(num-(c+d-e))