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())
g=fractions.gcd(c,d)
l=int(c*d/g)
x=b-a
cl=a//c
cg=b//c
dl=a//d
dg=b//d
ll=a//l
lg=b//l
print(cl,cg,dl,dg,lg,ll)
r=int(x+1-(cg-cl+dg-dl-lg+ll))
print(r)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
g=fractions.gcd(c,d)
l=int(c*d/g)
x=b-a
cd=x//c
dd=x/d
ld=x//l

r=int(x-(cd+dd-ld))
print(r)

Submission status: Wrong Answer

Solution code:
import math

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
def anti(A, B, m):
  ans = (B-A+1)//m
  mo = (B-A+1)%m
  if mo != 0 and mo >= A%m:
    ans += 1
  return ans

import fractions
g = fractions.gcd(C,D)
h = int((C*D)//g)
x = anti(A,B,C)
y = anti(A,B,D)
z = anti(A,B,h)
ans = B-A+1-x-y+z
print(ans)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
def anti(A, B, m):
  ans = (B-A+1)//m
  mo = (B-A+1)%m
  if mo != 0 and mo > A%m:
    ans += 1
  return ans

import fractions
g = fractions.gcd(C,D)
h = int((C*D)//g)
x = anti(A,B,C)
y = anti(A,B,D)
z = anti(A,B,h)
ans = B-A+1-x-y+z
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
a -= 1
from fractions import gcd
g = c*d//gcd(c,d)
cc = b//c-a//c
dc = b//d-a//d 
gc = b//g-a//b
print(b-a-cc-dc+gc)

Submission status: Wrong Answer

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

nums = b-a+1
t1 = ceil(b/c - a/c)
t2 = ceil(b/d - a/d)

lcm = (c*d)//gcd(c,d)
t3 = b//lcm - a//lcm
print(nums-t1-t2+t3)

Submission status: Wrong Answer

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

nums = b-a+1
t1 = b//c - a//c
t2 = b//d - a//d

lcm = (c*d)//gcd(c,d)
t3 = b//lcm - a//lcm
print(nums-t1-t2+t3)

Submission status: Wrong Answer

Solution code:
def gcd(n,m):
    if(n%m==0): return m
    else: return gcd(m,n%m)
a,b,c,d = map(int,input().split())
x = b-b//c-b//d+b//(c*d//gcd(c,d))
y = a-a//c-a//d+a//(c*d//gcd(c,d))
print(x-y)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int,input().split())
cab = (b//c)-((a-1)//c)
dab = (b//d)-((a-1)//c)
lcm = int(c*d/gcd(c,d))
cdab = (b//lcm)-((a-1)//lcm)
print((b-a+1)-cab-dab+cdab)

Submission status: Wrong Answer

Solution code:
## C - Anti-Division
from fractions import gcd
A, B, C, D = map(int, input().split())
s = B-A+1
t = B//C - (A-1)//C
u = B//D - (A-1)//D
v = B//( (C*D)//gcd(C,D) ) - (A-1)// (C*D)//gcd(C,D)
print(s - t - u + v)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

if a%c == 0:
    c_number = b // c - a // c + 1
else:
    c_number = b // c - a // c
if a%d == 0:
    d_number = b // d - a // d + 1
else:
    d_number = b // d - a // d
if a%(c*d) == 0:
    cd_number = b // (c*d / gcd(c,d)) - a // (c*d / gcd(c,d)) + 1
else:
    cd_number = b // (c*d / gcd(c,d)) - a // (c*d / gcd(c,d))
print(int((b-a+1) - (c_number + d_number - cd_number)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d=map(int,input().split())
count=b-a+1
temp1=b//c-(a-1)//c
temp2=b//d-(a-1)//d
temp3=b//((c*d)/gcd(c,d))-(a-1)//((c*d)/gcd(c,d))
print(int(count-temp1-temp2+temp3))

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

E = lcm(C, D)
CC = int(B / C) - int((A - 1) / C)
DC = int(B / D) - int((A - 1) / D)
EC = int(B / E) - int((A - 1) / E)

print(B - A + 1 - CC - DC + EC)

Submission status: Wrong Answer

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

print(int(B // C - A // C + B // D - A // D + B // C*D - A // C*D  ))

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d = map(int, input().split())
x = (b//c - (a - 0.1)//c)
y = (b//d - (a - 0.1)//d)
z = (b//((c * d)//fractions.gcd(c,d)) - (a - 0.1)//((c * d)//fractions.gcd(c,d)))

print(int((b - a + 1) - (x + y - z)))

Submission status: Wrong Answer

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

import fractions
lcmcd = a * b // fractions.gcd(c,d)
bc = b // c
ac = a // c
bd = b // d
ad = a // d
blcmcd = b // lcmcd
alcmcd = a // lcmcd

if a % c != 0:
    ac += 1
if a % d != 0:
    ad += 1
if a % lcmcd != 0:
    alcmcd += 1

print((b - a + 1) + 1 - ((bc - ac + 1) + (bd - ad + 1) - (blcmcd -alcmcd + 1)))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split())
import fractions
r = b-a+1
g = c * d // fractions.gcd(c, d)
ans_c = b//c - a//c
ans_d = b//d - a//d
ans_r = b//g - a//g
print(r - ans_c - ans_d + ans_r)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split())
import fractions
r = b-a+1
g = c * d // fractions.gcd(c, d)
ans_c = b//c - (a-1)//c
ans_d = b//d - (a-1)//d
ans_r = b//r - (a-1)//r
print(r - ans_c - ans_d + ans_r)

Submission status: Wrong Answer

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

print(r - r//c - r//d + r//g)

Submission status: Wrong Answer

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

print(r - r//c - r//d + r//g)

Submission status: Wrong Answer

Solution code:
import sys
import math

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

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


a,b,c,d = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
d = abs(d)
e = b - a + 1
f = int(b / c) - int((a - 1) / c)
g = int(b / d) - int((a - 1) / d)
cd = lcm(c, d)
h = int(b / cd) - int((a - 1) / cd)
n = e - f - g + h
print(n)

Submission status: Wrong Answer

Solution code:
import sys
import math
from fractions import gcd

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

a,b,c,d = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
e = b - a + 1
f = int(b / c) - int((a - 1) / c)
g = int(b / d) - int((a - 1) / d)
cd = lcm(c, d) 
h = int(b / cd) - int((a - 1) / cd)
n = e - f - g + h 
print(n)

Submission status: Wrong Answer

Solution code:
import sys
import math

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

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


a,b,c,d = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
e = b - a + 1
f = int(b / c) - int((a - 1) / c)
g = int(b / d) - int((a - 1) / d)
cd = lcm(c, d)
h = int(b / cd) - int((a - 1) / cd)
n = e - f - g + h
print(n)

Submission status: Wrong Answer

Solution code:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

import fractions

a,b,c,d = mi()

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

# cの倍数の個数
ac = int((a-1)/c)
bc = int(b/c)
nc = bc-ac

# dの倍数の個数
ad = int((a-1)/d)
bd = int(b/d)
nd = bd-ad

# cdのgcdの倍数の個数
ag = int((a-1)/g)
bg = int(b/g)
ng = bg-ag

ans = b-(a-1)-nc - nd + ng

# print(g,nc,nd,ng)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

A, B, C, D = map(int, input().split())
A -= 1
lcm = int(C / gcd(C, D) * D)
nA = A - (int(A/C) + int(A/D) - int(A/lcm))  
nB = B - (int(B/C) + int(B/D) - int(B/lcm))
print(nB - nA)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

A, B, C, D = map(int, input().split())
A -= 1
lcm = int(C*D / gcd(C, D))
nA = A - (int(A/C) + int(A/D) - int(A/lcm))  
nB = B - (int(B/C) + int(B/D) - int(B/lcm))
print(nB - nA)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
nbc = b // c
nac = (a - 1) // c
nc = nbc - nac
nbd = b // d
nad = (a - 1) // d
nd = nbd - nad
x, y = c, d
if x < y:
  x, y = y, x
  while x % y != 0:
    x, y = y, x % y
cd = (c * d) // y
nbcd = b // cd
nacd = (a - 1) // cd
ncd = nbcd - nacd
t = nc + nd - ncd
at = b - a + 1 - t
print(at)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
nbc = b // c
nac = (a - 1) // c
nc = nbc - nac
nbd = b // d
nad = (a - 1) // d
nd = nbd - nad
x, y = c, d
if x < y:
  x, y = y, x
  while x % y != 0:
    x, y = y, x % y
cd = (c * d) // y
nbcd = b // cd
nacd = a // cd
ncd = nbcd - nacd
t = nc + nd - ncd
at = b - a + 1 - t
print(at)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

lcm = int(C*D / gcd(C, D))
nA = A - (int(A/C) + int(A/D) - int(A/lcm))  
nB = B - (int(B/C) + int(B/D) - int(B/lcm))
print(nB - nA)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
nbc = b // c
nac = (a - 1) // c
nc = nbc - nac
nbd = b // d
nad = (a - 1) // d
nd = nbd - nad
x, y = c, d
if x < y:
  x, y = y, x
  while x % y != 0:
    x, y = y, x % y
cd = (c * d) // y
nbcd = b // cd
nacd = a // cd
ncd = nbcd - nacd
t = b - a + 1 - nc - nd + ncd
print(t)

Submission status: Wrong Answer

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

lcm = c*d/gcd(c,d)
print(b - a + 1 - int(b/c) + int((a-1)/c) - int(b/d) + int((a-1)/d) + int(b/lcm) - int((a-1)/lcm))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int,input().split())
e = (c*d)//gcd(c,d)
count = 0
if c != d:
    count =  (b-a)//c + (b-a)//d - (b-a)//e
else:
    count = (b-a)//c
print(b-a-count)

Submission status: Wrong Answer

Solution code:
import math

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

C, D = c, d
if C < D:
  C, D = D, C
r = C % D
while r > 0:
  C = D
  D = r
  r = C % D
lcm = c * d // D

cPower = b//c - math.ceil(a/c) + 1
dPower = b//d - math.ceil(a/d) + 1
cdPower = b//lcm - math.ceil(a/lcm) + 1

print((b-a+1) - cPower - dPower + cdPower)

Submission status: Wrong Answer

Solution code:
import math

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

C, D = c, d
if C < D:
  C, D = D, C
r = C % D
while r > 0:
  C = D
  D = r
  r = C % D
lcm = c * d // D

cPower = b//c - math.ceil(a/c) + 1
dPower = b//d - math.ceil(a/d) + 1
cdPower = b//lcm - a//lcm

print((b-a+1) - cPower - dPower + cdPower)

Submission status: Wrong Answer

Solution code:
# 判定機にmathがインストールされていないため、
# gcd=最小公倍数、lcm=最少公約数(返り値整数)を実装
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    z = None
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        return z


def lcm(m, n):
    return (m * n) // gcd(m, n)


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

# check
AB = B - (A - 1) 

C_cnt = B // C - (A - 1) // C
D_cnt = B // D - (A - 1) // C

lcm_CD = lcm(C, D)
lcm_cnt = B // lcm_CD - (A - 1) // lcm_CD

print(AB - C_cnt - D_cnt + lcm_cnt)

Submission status: Wrong Answer

Solution code:
li = list(map(int,input().split()))
countC = li[1] // li[2] - (li[0]-1) // li[2]

countD = li[1] // li[3] - (li[0]-1) // li[3]

countCD = li[1] // (li[2] * li[3]) - (li[0]-1) // (li[2] * li[3])

re = (li[1] - li[0] + 1) - (countC +countD - countCD)

# print(countC)
# print(countD)
# print(countCD)
print(re)

Submission status: Wrong Answer

Solution code:
li = list(map(int,input().split()))
countC = (li[1]-1) // li[2] - li[0] // li[2]

countD = (li[1]-1) // li[3] - li[0] // li[3]

countCD = (li[1]-1) // (li[2] * li[3]) - li[0] // (li[2] * li[3])

re = (li[1] - li[0] + 1) - (countC +countD - countCD)
print(re)

Submission status: Wrong Answer

Solution code:
li = list(map(int,input().split()))
countC = li[1] // li[2] - li[0] // li[2]
if li[0] % li[2] == 0:
  countC += 1

countD = li[1] // li[3] - li[0] // li[3]
if li[0] % li[3] == 0:
  countD += 1

countCD = li[1] // (li[2] * li[3]) - li[0] // (li[2] * li[3])
if li[0] % (li[2] * li[3]) == 0:
  countCD += 1

re = (li[1] - li[0] + 1) - (countC +countD - countCD)
print(re)

Submission status: Wrong Answer

Solution code:
li = list(map(int,input().split()))
countC = li[1] / li[2] - li[0] / li[2]
if li[0] % li[2] == 0:
  countC += 1
countD = li[1] / li[3] - li[0] / li[3]
if li[0] % li[3] == 0:
  countD += 1
countCD = li[1] / (li[2] * li[3]) - li[0] / (li[2] * li[3])
if li[0] % (li[2] * li[3]) == 0:
  countCD += 1
re = (li[1] - li[0] + 1) - (countC +countD - countCD)
print(re)

Submission status: Wrong Answer

Solution code:
import fractions
def lcm(n,m): return n*m//fractions.gcd(n,m)
A,B,C,D=map(int,input().split())
X=B-A; c=X//C; d=X//D; l=X//lcm(C,D)
print(X-c-d+l)

Submission status: Wrong Answer

Solution code:
import fractions
def lcm(n,m): return n*m//fractions.gcd(n,m)
A,B,C,D=map(int,input().split())
X=B-A
print((X-((X//C)+(X//D)))+(X//lcm(C,D)))

Submission status: Wrong Answer

Solution code:
import fractions
def lcm(n,m): return n*m//fractions.gcd(n,m)
A,B,C,D=map(int,input().split())
print(((B-A)-(((B-A)//C)+((B-A)//D)))+((B-A)//lcm(C,D)))

Submission status: Wrong Answer

Solution code:
from collections import Counter 
from collections import defaultdict
from collections import deque
import math
import itertools
import heapq
import numpy as np
import sys
sys.setrecursionlimit(10**6)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
input_list = lambda : list(map(int,input().split()))
import fractions

a,b,c,d=input_list()

l_c=math.ceil(a/c)
h_c=b//c
c_num=h_c-l_c+1

l_d=math.ceil(a/d)
h_d=b//d
d_num=h_d-l_d+1


g=c*d//fractions.gcd(c,d)
l_g=math.ceil(a/g)
h_g=b//g
g_num=h_g-l_g+1

ans=b-a+1-c_num-d_num+g_num
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

# lcm = lambda x, y: (x * y) / math.gcd(x, y)
lcm = lambda x, y: (x * y) / fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = il()
    E = B - A + 1
    cnt = 0

    cnt += B // C
    cnt += B // D
    cnt -= (A-1) // C
    cnt -= (A-1) // D

    cnt -= B // lcm(C, D)
    cnt += (A-1) // lcm(C, D)
    print(E - cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

# lcm = lambda x, y: x * y / math.gcd(x, y)
lcm = lambda x, y: x * y / fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = il()
    E = B - A + 1
    cnt = 0

    cnt += B // C
    cnt += B // D
    cnt -= (A-1) // C
    cnt -= (A-1) // D

    cnt -= B // lcm(C, D)
    cnt += (A-1) // lcm(C, D)
    print(E - cnt)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

# lcm = lambda x, y: x * y / math.gcd(x, y)
lcm = lambda x, y: x * y / fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = il()
    E = B - A + 1
    cnt = 0

    cnt += B // C
    cnt += B // D
    cnt -= (A-1) // C
    cnt -= (A-1) // D

    cnt -= B // lcm(C, D)
    cnt += (A-1) // lcm(C, D)
    print(E - int(cnt))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

# lcm = lambda x, y: x * y / math.gcd(x, y)
lcm = lambda x, y: x * y / fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = il()
    E = B - A + 1
    cnt = 0

    cnt += B // C
    cnt += B // D
    cnt -= (A-1) // C
    cnt -= (A-1) // D

    cnt -= B // lcm(C, D)
    cnt += A // lcm(C, D)
    print(E - int(cnt))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

# lcm = lambda x, y: x * y / math.gcd(x, y)
lcm = lambda x, y: x * y / fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = il()
    E = B - A + 1
    cnt = 0

    cnt += B // C
    cnt += B // D
    cnt -= A // C
    cnt -= A // D

    cnt -= B // lcm(C, D)
    cnt += A // lcm(C, D)
    print(E - int(cnt))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
nums = input()
intNums = []

def saidaiKouYaku(a, b):
    if a < b:
        tmp = a
        a = b
        b = tmp

    r = a % b
    while(r != 0):
        a = b
        b = r
        r = a % b
    return b


for n in nums.split():
    intNums.append(int(n))
    
if len(intNums) == 4 and intNums[0] <= intNums[1] \
    and (intNums[0] >= 1 and intNums[0] <= 10**18) \
    and (intNums[1] >= 1 and intNums[1] <= 10**18) \
    and (intNums[2] >= 1 and intNums[2] <= 10**9) \
    and (intNums[3] >= 1 and intNums[3] <= 10**9):

    # 逆にどちらかで割り切れる数を調べる
    # C,D の最大公約数
    saidaiKouYaku = saidaiKouYaku(intNums[2], intNums[3])
    
    # C,Dの最小公倍数は　積 / 最大公約数
    saisyoKoubai = intNums[2] * intNums[3] // saidaiKouYaku
#     print('saidaiKouYaku = ',saidaiKouYaku)
#     print('saisyoKoubai = ',saisyoKoubai)
    c1 = intNums[1] // intNums[2] - intNums[0] // intNums[2]
    c2 = intNums[1] // intNums[3] - intNums[0] // intNums[3]
    c3 = intNums[1] // saisyoKoubai - intNums[0] // saisyoKoubai
#     print(c1)
#     print(c2)
#     print(c3)
    c4 = c1 + c2 - c3
    result = (intNums[1] - (intNums[0]-1)) - c4
    print(result)

Submission status: Wrong Answer

Solution code:
nums = input()
intNums = []

def saidaiKouYaku(a, b):
    if a < b:
        tmp = a
        a = b
        b = tmp
    r = a % b
    while(r != 0):
        a = b
        b = r
        r = a % b
    return b


for n in nums.split():
    intNums.append(int(n))
    
if len(intNums) == 4 and intNums[0] <= intNums[1] \
    and (intNums[0] >= 1 and intNums[0] <= 10**18) \
    and (intNums[1] >= 1 and intNums[1] <= 10**18) \
    and (intNums[2] >= 1 and intNums[2] <= 10**9) \
    and (intNums[3] >= 1 and intNums[3] <= 10**9):

    # 逆にどちらかで割り切れる数を調べる
    # C,D の最大公約数
    saidaiKouYaku = saidaiKouYaku(intNums[2], intNums[3])
    
    # C,Dの最小公倍数は　積 / 最大公約数
    saisyoKoubai = intNums[2] * intNums[3] // saidaiKouYaku
#     print('saidaiKouYaku = ',saidaiKouYaku)
#     print('saisyoKoubai = ',saisyoKoubai)
    c1 = intNums[1] // intNums[2] - intNums[0] // intNums[2]
    c2 = intNums[1] // intNums[3] - intNums[0] // intNums[3]
    c3 = intNums[1] // saisyoKoubai - intNums[0] // saisyoKoubai
#     print(c1)
#     print(c2)
#     print(c3)
    c4 = c1 + c2 - c3
    result = (intNums[1] - (intNums[0]-1)) - c4
    print(result)

Submission status: Wrong Answer

Solution code:
nums = input()
intNums = []
for n in nums.split():
    intNums.append(int(n))

if len(intNums) == 4 and intNums[0] <= intNums[1] \
    and (intNums[0] >= 1 and intNums[0] <= 10**18) \
    and (intNums[1] >= 1 and intNums[1] <= 10**18) \
    and (intNums[2] >= 1 and intNums[2] <= 10**9) \
    and (intNums[3] >= 1 and intNums[3] <= 10**9):

    # 逆にどちらかで割り切れる数を調べる     
    c1 = intNums[1] // intNums[2] - intNums[0] // intNums[2]
    c2 = intNums[1] // intNums[3] - intNums[0] // intNums[3]
    c3 = intNums[1] // (intNums[2]*intNums[3]) - intNums[0] // (intNums[2]*intNums[3])
#     print(c1)
#     print(c2)
#     print(c3)
    c4 = c1 + c2 - c3
    result = (intNums[1] - (intNums[0]-1)) - c4
    print(result)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
cwari=b//c-(a-1)//c
dwari=b//d-(a-1)//d
cdwari=b//(c*d)-(a-1)//(c*d)
ans=(b-a)+1-cwari-dwari+cdwari
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())

if A % C ==0:
    c = (B//C) - (A//C) +1
else:
    c = (B//C) - (A//C)

if A % D ==0:
    d = (B//D) - (A//D) +1
else:
    d = (B//D) - (A//D)

E = lcm(C,D)

if A % E ==0:
    e = (B//E) - (A//E) +1
else:
    e = (B//E) - (A//E)

print(c,d,e)
print(B-A+1-c-d+e)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri May 15 00:52:33 2020

@author: Kanaru Sato
"""

import fractions

def divnum(x,y,n):
    if x%n == 0:
        return y//n - x//n + 1
    else:
        return y//n - x//n

a,b,c,d = list(map(int,input().split()))
cd = (c*d)/fractions.gcd(c,d)
ans = divnum(a,b,c) + divnum(a,b,d) - divnum(a,b,cd)
print(int(b-a+1-ans))

Submission status: Wrong Answer

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

c_b = int(b / c)
c_a = int((a-1)/c)
d_b = int(b/d)
d_a = int((a-1)/d)
cd_b =int(b / (c * d))
cd_a = int((a-1)/(c * d))

c_ans = c_b - c_a
d_ans = d_b - d_a
cd_ans = cd_b - cd_a
ans = c_ans + d_ans - cd_ans
print(b - a + 1 - ans)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int,input().split())
x=b//c-a//c
y=b//d-a//d
g=math.gcd(c,d)
l=c*d//g
z=b//l-a//l
print(b-a+1-x-y+z)

Submission status: Wrong Answer

Solution code:

import fractions
def anti_division(a, b, c, d):

    ans = b-a+1
    cd = a*b // fractions.gcd(a, b)
    ccount = ((b+c)//c) - ((a+c)//c)
    dcount = ((b+d)//d) - ((a+d)//d)
    cdcount = ((b+cd)//cd) - ((a+cd)//cd)
    return ans-ccount-dcount+cdcount
def main():
    a, b, c, d = map(int, input().split())
    print(anti_division(a, b, c, d))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import floor

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

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

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


Cdiff = floor(B/C) - floor((A-1)/C)
Ddiff = floor(B/D) - floor((A-1)/D)

CD = lcm(C,D)
CDdiff = floor(B/CD) - floor((A-1)/CD)



res = Cdiff+Ddiff-CDdiff
print((B-A+1)-res)

Submission status: Wrong Answer

Solution code:
from math import ceil

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


Cdiff = ceil(B/C) - ceil((A-1)/C)
Ddiff = ceil(B/D) - ceil((A-1)/D)

CDdiff = ceil(B/(C*D) ) - ceil((A-1)/(C*D))

res = Cdiff+Ddiff-CDdiff
print((B-A)-res)

Submission status: Wrong Answer

Solution code:
from math import ceil

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


Cdiff = ceil(B/C) - ceil((A-1)/C)
Ddiff = ceil(B/D) - ceil((A-1)/D)

CDdiff = ceil(B/(C*D) ) - ceil((A-1)/(C*D))

res = Cdiff+Ddiff-CDdiff
print((B-A+1)-res)

Submission status: Wrong Answer

Solution code:
import fractions

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


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

#間の数の個数
num = B - A + 1

CD = lcm(C, D)

c = int(num/C)
if num%C != 0 and (num%C > A%C or num%C > (C-(A%C))):
    c += 1

d = int(num/D)
if num%D != 0 and (num%D > A%D or num%D > (D-(A%D))):
    d += 1

cd = int(num/CD)
if num%CD != 0 and (num%CD > A%CD or num%CD > (CD-(A%CD))):
    cd += 1

ans = num - (c + d - cd)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

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


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

#間の数の個数
num = B - A + 1

CD = lcm(C, D)

c = int(num/C)
if num%C != 0 and (num%C > A%C or num%C > (C-A%C)):
    c += 1

d = int(num/D)
if num%D != 0 and (num%D > A%D or num%D > (D-A%D)):
    d += 1

cd = int(num/CD)
if num%CD != 0 and (num%CD > A%CD or num%CD > (CD-A%CD)):
    cd += 1

ans = num - (c + d - cd)
print(ans)

Submission status: Wrong Answer

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod=10**9+7

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

def lcm(a, b):
    return a // gcd(a, b) * b
a,b,c,d=MI()
u=lcm(c,d)
#print(u)
#1~x mod y==0
'''def div(x,y):
    return int(x/y) '''
'''ansb=b-div(b,c)-div(b,d)+div(b,u)
ansa=a-1-div(a-1,c)-div(a-1,d)+div(a-1,u)'''
ansb=b-int(b/c)-int(b/d)+int(b/u)
ansa=a-1-int((a-1)/c)-int((a-1)/d)+int((a-1)/u)

print(ansb-ansa)
mod = 10**9 + 7

Submission status: Wrong Answer

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod=10**9+7

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

def lcm(a, b):
    return a // gcd(a, b) * b
a,b,c,d=MI()
u=lcm(c,d)
#print(u)
#1~x mod y==0
def div(x,y):
    return int(x/y) 
ansb=b-div(b,c)-div(b,d)+div(b,u)
ansa=a-1-div(a-1,c)-div(a-1,d)+div(a-1,u)
print(ansb-ansa)
mod = 10**9 + 7

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())
#N(C cup d) = N(C)+N(D) - N(C cap D)
# N(C)
X = b//c
Y = a//c
C =(X-Y)
# N(D)
x = b//d
y = a//d
D =(x-y)
# N(C cap D)
def lcm(x,y):
  return (x*y) // fractions.gcd(x,y)
koubaisu = lcm(c,d)
alpha = b//koubaisu
bata = a//koubaisu
E = alpha - bata
ans_1 = C+D-E
ans_2 = (b-a+1)-ans_1
print(ans_2)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())
e,f,g,h,i,j = b//c,b//d,(a-1)//c,(a-1)//d,b//((c*d)/fractions.gcd(c,d)),(a-1)//((c*d)/fractions.gcd(c,d))
print(int(b-(e+f-i)-(a-1-(g+h-j))))

Submission status: Wrong Answer

Solution code:
def resolve():
    from fractions import gcd
    a, b, c, d = map(int, input().split())
    e = c*d/gcd(c,d)
    db = b - b//c - b//d + b//e
    da = a-1 - (a-1)//c - (a-1)//d + (a-1)//e
    print(int(db-da))
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    from fractions import gcd
    a, b, c, d = map(int, input().split())
    e = int(c*d/gcd(c,d))
    db = int(b - (int(b/c) + int(b/d) - int(b/e)))
    da = int((a-1) - (int((a-1)/c) + int((a-1)/d) - int((a-1)/e)))
    print(int(db-da))
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    from fractions import gcd
    a, b, c, d = map(int, input().split())
    e = int(c*d/gcd(c,d))
    db = int(b - (int(b/c) + int(b/d) - int(b/e)))
    da = int((a-1) - (int((a-1)/c) + int((a-1)/d) - int((a-1)/e)))
    print(int(db-da))

Submission status: Wrong Answer

Solution code:
def resolve():
    from fractions import gcd
    a, b, c, d = map(int, input().split())
    e = c*d/gcd(c,d)
    db = int(b - (int(b/c) + int(b/d) - int(b/e)))
    da = int((a-1) - (int((a-1)/c) + int((a-1)/d) - int((a-1)/e)))
    print(int(db-da))
resolve()