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 as fr 
a,b,c,d=map(int,input().split())
lcm=(c*d)/fr.gcd(c,d)
cc=0
dd=0
cd=0
if a%c == 0:
  cc += b//c - a/c + 1
else:
  cc += b//c - a//c

if a%d == 0:
  dd += b//d - a/d + 1
else:
  dd += b//d - a//d

if a%lcm == 0:
  cd += b//lcm - a/lcm + 1
else:
  cd += b//lcm - a//lcm  

print(int(cc+dd-cd))

Submission status: Wrong Answer

Solution code:
import fractions as fr 
a,b,c,d=map(int,input().split())
lcm=(c*d)/fr.gcd(c,d)
cc=0
dd=0
cd=0
if a%c == 0:
  cc += b//c - a/c + 1
else:
  cc += b//c - a//c

if a%d == 0:
  dd += b//d - a/d + 1
else:
  dd += b//d - a//d

if a%lcm == 0:
  cd += b//lcm - a/lcm + 1
else:
  cd += b//lcm - a//lcm  

print(cc+dd-cd)

Submission status: Wrong Answer

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

import math

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

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

def myfunc(x, div1, div2):
    div3 = lcm(div1, div2)
    return x-int(x/div1)-int(x/div2)+int(x/div3)

print(myfunc(B, C, D)-myfunc(A-1, C, D))

Submission status: Wrong Answer

Solution code:
# a から bで　cでもdでも割り切れないものの数を調べる
from fractions import gcd
Input = input()
a, b, c, d = Input.split()
a, b, c, d = int(a), int(b), int(c), int(d)
c_min = int(a/c) if a % c == 0 else int(a/c) + 1
c_max = int(b/c)
delta_c = c_max - c_min + 1
d_min = int(a/d) if a % c == 0 else int(a/d) + 1
d_max = int(b/d)
delta_d = d_max - d_min + 1
def lcm(x, y):
    return (x * y) // gcd(x, y)
cd = lcm(c, d)
cd_min = int(a/cd) if a % cd == 0 else int(a/cd) + 1
cd_max = int(b/cd)
delta_cd = cd_max -cd_min + 1
num_cd = delta_c + delta_d - delta_cd
print( b-a+1 - num_cd, end='')

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
    if x<y:
        x,y=y,x
    if y==0:
        return x
    c=x%y
    return gcd(y,c)   

a,b,c,d =map(int,input().split())
tmp = c * d / gcd(c,d)
maxt = b-a+1
maxt = maxt - (b//c - a//c+ int(a%c==0)) - (b//d - a//d + int(a%d==0)) + (b//tmp - a//tmp)  

print(int(maxt))

Submission status: Wrong Answer

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

import math

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

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

def myfunc(x, div1, div2):
    div3 = lcm(div1, div2)
    return x-math.floor(x/div1)-math.floor(x/div2)+math.floor(x/div3)

print(myfunc(B, C, D)-myfunc(A-1, C, D))

Submission status: Wrong Answer

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

if A%C==0:
    Cst=A//C
else:
    Cst=A//C+1
Cen=B//C

if A%D==0:
    Dst=A//D
else:
    Dst=A//D+1
Den=B//D
if A%(C*D)==0:
    CDst=A//(C*D)
else:
    CDst=A//(C*D)+1
CDen=B//(C*D)
print(B-A+1-(Cen-Cst+1)-(Den-Dst+1)+(CDen-CDst+1))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d=map(int,input().split())
c0=b//c-(a-1)//c
d0=b//d-(a-1)//d
cd0=b//(c*d//gcd(c,d))-a//(c*d//gcd(c,d))
print(b-a+1-c0-d0+cd0)

Submission status: Wrong Answer

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

if C == 1 and D == 0 :
  print(0)
elif D == 1 and C == 0 :
  print(z)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
Input = input()
a, b, c, d = Input.split()
a, b, c, d = int(a), int(b), int(c), int(d)
c_min = int(a/c) if a % c == 0 else int(a/c) + 1
c_max = int(b/c)
delta_c = c_max - c_min + 1
d_min = int(a/d) if a % c == 0 else int(a/d) + 1
d_max = int(b/d)
delta_d = d_max - d_min + 1
def lcm(x, y):
    return (x * y) // gcd(x, y)
cd = lcm(c, d)
cd_min = int(a/cd) if a % c == 0 else int(a/cd) + 1
cd_max = int(b/cd)
delta_cd = cd_max -cd_min + 1
num_cd = delta_c + delta_d - delta_cd
print( b-a+1 - num_cd, end='')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

ans = B - A + 1

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

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

print(int(ans))

Submission status: Wrong Answer

Solution code:
import fractions,math

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

Submission status: Wrong Answer

Solution code:
import fractions,math

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import math

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

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

def myfunc(x, div1, div2):
    div3 = lcm(div1, div2)
    return x-(math.floor(x/div1)+math.floor(x/div2)-math.floor(x/div3))

print(myfunc(B, C, D)-myfunc(A-1, C, D))

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

if D == 1 :
  ans = 0
else :
  ans = B - A + 1

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

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

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

if C == 1 :
    ans = 0
else :
    ans = B - A + 1

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

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

print(int(ans))

Submission status: Wrong Answer

Solution code:
import fractions
import numpy as np
import os
import sys

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

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

A0=A//C
B0=B//C
if(A%C==0):
    B0+=1
C0=B0-A0


A1=A//D
B1=B//D
if(A%D==0):
    B1+=1
D1=B1-A1

A2=A//E
B2=B//E
if(A%E==0):
    B2+=1
E2=B2-A2

if(C==1 or D==1):
    print(0)
else:
    print("{:.0f}".format((B-A+1)-(C0+D1-E2)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

CD_lcm = (C * D) / gcd(C, D)


def divided(a, b, target):
    return b // target - (a - 1) // target


all_num = B - A + 1

div_t1 = divided(A, B, C)
div_t2 = divided(A, B, D)
div_extra = divided(A, B, CD_lcm)

print(all_num - div_t1 - div_t2 + div_extra)

Submission status: Wrong Answer

Solution code:
# from fractions import gcd
# from math import ceil,floor
#
# A,B,C,D=map(int, input().split())
#
# Cans = B//C - (A-1)//C
# Dans = B//D - (A-1)//D
#
# CD = C * D // gcd(C,D)
# CDans = B//CD - (A-1)//CD
#
# ans = (B-A+1) - (Cans + Dans - CDans)
#
# print(ans)
def gcd(a,b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

def main():
    A,B,C,D=input().split()
    A=int(A)
    B=int(B)
    C=int(C)
    D=int(D)
    if A%C!=0:
        C_min=A-A%C+C
    else:
        C_min=A
    C_max=B-B%C
    if A%D!=0:
        D_min=A-A%D+D
    else:
        D_min=A
    D_max=B-B%D
    if A%(C*D/gcd(C,D))!=0:
        CD_min=A-A%(C*D/gcd(C,D))+(C*D/gcd(C,D))
    else:
        CD_min=A
    CD_max=B-B%(C*D/gcd(C,D))
    C_sum=(C_max-C_min)/C+1
    D_sum=(D_max-D_min)/D+1
    CD_sum=(CD_max-CD_min)/(C*D/gcd(C,D))+1
    sum= B-A+1-int(C_sum+D_sum-CD_sum)
    return sum

print(main())

Submission status: Wrong Answer

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

def main():
    A,B,C,D=input().split()
    A=int(A)
    B=int(B)
    C=int(C)
    D=int(D)
    if A%C!=0:
        C_min=A-A%C+C
    else:
        C_min=A
    C_max=B-B%C
    print(C_max,C)
    if A%D!=0:
        D_min=A-A%D+D
    else:
        D_min=A
    D_max=B-B%D
    if A%(C*D/gcd(C,D))!=0:
        CD_min=A-A%(C*D/gcd(C,D))+(C*D/gcd(C,D))
    else:
        CD_min=A
    CD_max=B-B%(C*D/gcd(C,D))
    C_sum=(C_max-C_min)/C+1
    D_sum=(D_max-D_min)/D+1
    CD_sum=(CD_max-CD_min)/(C*D/gcd(C,D))+1
    sum= B-A+1-int(C_sum+D_sum-CD_sum)
    return sum

print(main())

Submission status: Wrong Answer

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

if a < 0 or b < 0 or c < 0 or d < 0:
    print("wrong case", a, b, c, d)

print(3)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d=map(int,input().split())
s=b-a+1
c0=s//c
d0=s//d
cd0=s//(c*d//gcd(c,d))
print(s-c0-d0+cd0)

Submission status: Wrong Answer

Solution code:
import fractions
import numpy as np
import os
import sys

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

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

A0=A//C
B0=B//C
if(A%C==0):
    B0+=1
C0=B0-A0


A1=A//D
B1=B//D
if(A%D==0):
    B1+=1
D1=B1-A1

A2=A//E
B2=B//E
if(A%E==0):
    B2+=1
E2=B2-A2

if(C==1 or D==1):
    print(0)
else:
    print((B-A+1)-(C0+D1-E2))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import fractions

def solve(A: int, B: int, C: int, D: int):
    ci = int(B/C) - int((A-1)/C)
    di = int(B/D) - int((A-1)/D)
    l = int(C*D // fractions.gcd(C,D))
    xi = int(B/l) - int((A-1)/l)

    # print(ci,di,xi)
    print(B-A+1-ci-di+xi)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import fractions,math

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

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

if C == 1 or D == 1 :
    ans = 0
else :
    ans = B - A + 1

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

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

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

ans = B - A + 1

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

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

print(int(ans))

Submission status: Wrong Answer

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

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

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

pot = i + j - k

print(b-(a-1)-pot)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

ans = B - A + 1

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

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

print(ans)

Submission status: Wrong Answer

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

cko = b//c - (a-1)//c
dko = b//d - (a-1)//d
eko = b//e - (a-1)//e
print(b-a+1-cko-dko+eko)

Submission status: Wrong Answer

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

import math

interval = B-A+1

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

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

def myfunc(x, div1, div2):
    div3 = lcm(div1, div2)
    return x-(math.floor(x/div1)+math.floor(x/div2)-math.floor(x/div3))

print(myfunc(B, C, D)-myfunc(A-1, C, D))

Submission status: Wrong Answer

Solution code:
import fractions

def f(x, c, d):
    lcm_num = c*d / fractions.gcd(c, d)
    return x - x//c - x//d + x//lcm_num

a, b, c, d = map(int, input().split())
print(int(f(b, c, d) - f(a-1, c, d)))

Submission status: Wrong Answer

Solution code:
import fractions

def f(x, c, d):
    lcm_num = c*d / fractions.gcd(c, d)
    return x - x//c - x//d + x//lcm_num

a, b, c, d = map(int, input().split())
print(f(b, c, d) - f(a-1, c, d))

Submission status: Wrong Answer

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

def getLCM(a, b):
    r = -1

    if C > D:
        a = C
        b = D
    else:
        a = D
        b = C

    while True:
        r = a % b
        if r == 0:
            b = int(C*D/b)
            return b
        a = b
        b = r

E = 1
if C != D:
    if C > D:
        E = getLCM(C, D)

    elif D > C:
        E = getLCM(D, C)

    c = int(B / C)
    d = int(B / D)
    e = int(B / E)
    ans1 = (B-c-d+e)

    c = int((A-1) / C)
    d = int((A-1) / D)
    e = int((A-1) / E)
    ans2 = ((A-1)-c-d+e)
else:
    c = int(B / C)
    ans1 = (B-c)

    c = int((A-1) / C)
    ans2 = ((A-1)-c)

ans = ans1 - ans2
if ans < 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions,math

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

Submission status: Wrong Answer

Solution code:
import math
import fractions
A, B, C, D = map(int, input().split())
CD = math.ceil(C * D // fractions.gcd(C, D))
AC = math.ceil(A // C)
BC = math.ceil(B // C)
C = BC - AC + 1
AD = math.ceil(A // D)
BD = math.ceil(B // D)
D = BD - AD + 1
ACD = math.ceil(A // CD)
BCD = math.ceil(B // CD)
CD = BCD - ACD + 1
print((B-A+1) - (C + D - CD))

Submission status: Wrong Answer

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

import math

interval = B-A+1

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

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

def myfunc(x, div1, div2):
    div3 = lcm(div1, div2)
    return math.floor(x/div1)+math.floor(x/div2)-math.floor(x/div3)

print(interval-(myfunc(B, C, D)-myfunc(A-1, C, D)))

Submission status: Wrong Answer

Solution code:
import fractions,math

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

Submission status: Wrong Answer

Solution code:
import math
import fractions

A, B, C, D = map(int, input().split())
E = (C * D) // fractions.gcd(C, D)
count_div = 0

# n = (A-1) // C
n = math.ceil(A / C) - 1
m = B // C
if m >= n:
  count_div += m - n

# l = (A-1) // D
l = math.ceil(A / D) - 1
k = B // D
if k >= l:
  count_div += k - l

# j = (A-1) // E
j = math.ceil(A / E) - 1
i = B // E
if i >= j:
  count_div -= i - j

print(B - A + 1 - count_div)

Submission status: Wrong Answer

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

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

x = int(b/c) -int((a-1)/c)
y = int(b/d) -int((a-1)/d)
lcm_xy = int(c*d/gcd(c,d))
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)

print(al-(x+y-xy))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import time
import re
import math
import fractions
 
def main():
    A,B,C,D=map(int,input().split())
    N=B-A+1
    sc=hoge(A,C)-A+1
    if sc<=N:
        ccount=(N+C-sc)//C
    else:
       ccount=0
 
    sd=hoge(A,D)-A+1
    if sd<=N:
        dcount=(N+D-sd)//D
    else:
       dcount=0
 
    CD=C * D // fractions.gcd(C, D)
    scd=hoge(A,CD)-A+1
    if scd<=N:
        cdcount=(N+CD-scd)//CD
    else:
       cdcount=0
    print(N-(ccount+dcount-cdcount))
 
 
def hoge(a,b):
    if a%b==0:
        return b
    else:
        #print("({} // {} +1)*{} {}".format(a,b,b,(a//b+1)*b))
        return (a//b+1)*b
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B

Submission status: Wrong Answer

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

def getLCM(a, b):
    r = -1

    if C > D:
        a = C
        b = D
    else:
        a = D
        b = C

    while True:
        r = a % b
        if r == 0:
            b = int(C*D/b)
            return b
        a = b
        b = r

E = 1
if C != D:
    if C > D:
        E = getLCM(C, D)

    elif D > C:
        E = getLCM(D, C)

    c = int(B / C)
    d = int(B / D)
    e = int(B / E)
    ans1 = (B-c-d+e)

    c = int((A-1) / C)
    d = int((A-1) / D)
    e = int((A-1) / E)
    ans2 = ((A-1)-c-d+e)
else:
    c = int(B / C)
    ans1 = (B-c)

    c = int((A-1) / C)
    ans2 = ((A-1)-c)

ans = ans1 - ans2
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
import math

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

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

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

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
a, b, c, d = [int(i) for i in input().split()]
c1 = d if c < d else c
d1 = c if c < d else d
while d1 != 0:
    e = d1
    d1 = c1 % d1
    c1 = e
e = c * d / e
a -= 1
cnt = (b - a) + int(b // e) - int(a // e) - int(b // c) + int(a // c) - int(b // d) + int(a // d)
print(cnt)

Submission status: Wrong Answer

Solution code:
def f(n, div):
    return n // div


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

div_c = f(b, c) - f(a - 1, c)
div_d = f(b, d) - f(a - 1, d)
div_cd = f(b, c * d) - f(a - 1, c * d)

print(b - a + 1 - div_c - div_d + div_cd)

Submission status: Wrong Answer

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

def getLCM(a, b):
    r = -1

    if C > D:
        a = C
        b = D
    else:
        a = D
        b = C

    while True:
        r = a % b
        if r == 0:
            b = int(C*D/b)
            return b
        a = b
        b = r

E = 1
if C > D:
    E = getLCM(C, D)
else:
    E = getLCM(D, C)

c = int(B / C)
d = int(B / D)
e = int(B / E)
ans1 = (B-c-d+e)

c = int((A-1) / C)
d = int((A-1) / D)
e = int((A-1) / E)
ans2 = ((A-1)-c-d+e)

ans = ans1 - ans2
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import fractions

A, B, C, D = map(int, input().split())
E = (C * D) // fractions.gcd(C, D)
count_div = 0
 
# n = (A-1) // C
n = math.ceil(A / C) - 1
m = B // C
count_div += m - n

# l = (A-1) // D
l = math.ceil(A / D) - 1
k = B // D
count_div += k - l

# j = (A-1) // E
j = math.ceil(A / E) - 1
i = B // E
count_div -= i - j

print(B - A + 1 - count_div)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
a, b, c, d = [int(i) for i in input().split()]
c1 = d if c < d else c
d1 = c if c < d else d
while d1 != 0:
    e = d1
    d1 = c1 % d1
    c1 = e
e = c * d / e
a -= 1
cnt = (b - a) + b // e - a // e - b // c + a // c - b // d + a // d
print(cnt)

Submission status: Wrong Answer

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

import math
a = [int(i) for i in input().split()]

sup_c = math.floor(a[1]/a[2])
sup_d = math.floor(a[1]/a[3])
low_c = math.floor((a[0]-1)/a[2])
low_d = math.floor((a[0]-1)/a[3])

g = gcd(a[3],a[2])
l = int((a[2]*a[3])/g)
num_l1 = math.floor(a[1]/l)
num_l2 = math.floor((a[0]-1)/l)

maximum = a[1]-(sup_c+sup_d)+num_l1
minimum = (a[0]-1)-(low_c+low_d)+num_l2

answer = maximum - minimum
print(answer)

Submission status: Wrong Answer

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


f=(a//c) 
g=(b//c) 
h=(a//d) 
k=(b//d) 
l=(a//e)
m=(b//e)
x=b-a
y=g-f
z=k-h
w=m-l

print(round(x-y-z+w))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import time
import re
import math
import fractions
 
def main():
    A,B,C,D=map(int,input().split())
    N=B-A+1
    sc=hoge(A,C)-A+1
    if sc<=N:
        ccount=(N+C-sc)//C
    else:
       ccount=0
 
    sd=hoge(A,D)-A+1
    if sd<=N:
        dcount=(N+D-sd)//D
    else:
       dcount=0
 
    CD=C * D / fractions.gcd(C, D)
    scd=hoge(A,CD)-A+1
    if scd<=N:
        cdcount=(N+CD-scd)//CD
    else:
       cdcount=0
    print(N-(ccount+dcount-cdcount))
 
 
def hoge(a,b):
    if a%b==0:
        return b
    else:
        return (a//b+1)*b
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D=map(int,input().split())
setAB=range(A,B+1)
setC=range(A,B+1,C)
setD=range(A,B+1,D)
setCD=range(A,B+1,C*D//fractions.gcd(C,D))
lenAB=len(setAB)
lenC=len(setC)
lenD=len(setD)
lenCD=len(setCD)
ans=lenAB-lenC-lenD+lenCD
print(ans)

Submission status: Wrong Answer

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

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


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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import time
import re
import math
import fractions
 
def main():
    A,B,C,D=map(int,input().split())
    N=B-A+1
    sc=hoge(A,C)-A+1
    if sc<=N:
        ccount=(N+C-sc)//C
    else:
       ccount=0
 
    sd=hoge(A,D)-A+1
    if sd<=N:
        dcount=(N+D-sd)//D
    else:
       dcount=0
 
    CD=C * D / fractions.gcd(C, D)
    scd=hoge(A,CD)-A+1
    if scd<=N:
        cdcount=(N+CD-scd)//CD
    else:
       cdcount=0
    print(N-(ccount+dcount-cdcount))
 
 
def hoge(a,b):
    return math.ceil(a/b)*b
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import fractions
import math

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

C_ = len(range((A//C)*C,B+1,C))
D_ = len(range((A//D)*D,B+1,D))
CD = (C*D) // fractions.gcd(C, D)
CD_ = len(range((A//CD)*CD,B+1,CD))

print(B-A+1-C_-D_+CD_)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

if A == B:
    print(0)
    exit()

CD_lcm = C * D // gcd(C, D)

n_cant_divs = []
for target in [C, D, CD_lcm]:
    if B < target:
        n_cant_divs.append(A - B + 1)
    if A <= target <= B:
        t_cant_div = target - A
        can_div = B // target
        t_cant_div2 = (B - target + 1) - can_div
        n_cant_divs.append(t_cant_div + t_cant_div2)
    elif target < A:
        can_div_w_over = B // target
        correction = (A - 1) // target
        actual_can_div = can_div_w_over - correction
        t_cant_div = (B - A + 1) - actual_can_div
        n_cant_divs.append(t_cant_div)

print(n_cant_divs[0] + n_cant_divs[1] - n_cant_divs[2])

Submission status: Wrong Answer

Solution code:
a, b, c, d = [int(i) for i in input().split()]
c1, d1 = [d if c < d else c, c if c < d else d]
while d1 > 0:
    e = d1
    d1 = c1 % d1
    c1 = e
e = c * d / e
cnt = (b - a + 1) + int(b / e) - int((a-1) / e) - int(b / c) + int((a-1) / c) - int(b / d) + int((a-1) / d)
print(cnt)

Submission status: Wrong Answer

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


f=math.ceil(a/c) 
g=math.ceil(b/c) 
h=math.ceil(a/d) 
k=math.ceil(b/d) 
l=math.ceil(a/e)
m=math.ceil(b/e)
x=b-a
y=g-f
z=k-h
w=m-l

print(round(x-y-z+w))

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 = 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(int(ans))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
a, b, c, d = [int(i) for i in input().split()]
c1, d1 = [d if c < d else c, c if c < d else d]
while d1 > 0:
    e = d1
    d1 = c1 % d1
    c1 = e
e = c * d / e
print(e)
cnt = (b - a + 1) + int(b / e) - int((a-1) / e) - int(b / c) + int((a-1) / c) - int(b / d) + int((a-1) / d)
print(cnt)

Submission status: Wrong Answer

Solution code:
import fractions,math

lis=list(map(int,input().split()))
gCD=fractions.gcd(lis[2],lis[3])
CD=int((lis[3]/gCD)*lis[2])
lis[0]=lis[0]-1
AmodC=lis[0]%lis[2]
AC=lis[0]-AmodC
AmodD=lis[0]%lis[3]
AD=lis[0]-AmodD
AmodCD=lis[0]%CD
ACD=lis[0]-AmodCD

BmodC=lis[1]%lis[2]
BC=lis[1]-BmodC
BmodD=lis[1]%lis[3]
BD=lis[1]-BmodD
BmodCD=lis[1]%CD
BCD=lis[1]-BmodCD



ans=int((lis[1]-(BC/lis[2]+BD/lis[3]-BCD/CD))-(lis[0]-(AC/lis[2]+AD/lis[3]-ACD/CD)))

print(ans)
#print(AC,AD,BC,BD,ACD,BCD)

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

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

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

n = A-1 // C
m = B // C
count_div += m - n

l = A-1 // D
k = B // D
count_div += k - l

j = A-1 / lcm(C, D)
i = B // lcm(C, D)
count_div -= i - j

print(B - A + 1 - count_div)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = (c * d / gcd(c, d))
print(e)


f=math.ceil(a/c) 
g=math.ceil(b/c) 
h=math.ceil(a/d) 
k=math.ceil(b/d) 
l=math.ceil(a/e)
m=math.ceil(b/e)
x=b-a
y=g-f
z=k-h
w=m-l

print(round(x-y-z+w))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

CD_lcm = C * D // gcd(C, D)

n_cant_divs = []
for target in [C, D, CD_lcm]:
    if B < target:
        n_cant_divs.append(A - B + 1)
    if A <= target <= B:
        t_cant_div = target - A
        can_div = B // target
        t_cant_div2 = (B - target + 1) - can_div
        n_cant_divs.append(t_cant_div + t_cant_div2)
    elif target < A:
        can_div_w_over = B // target
        correction = (A - 1) // target
        actual_can_div = can_div_w_over - correction
        t_cant_div = (B - A + 1) - actual_can_div
        n_cant_divs.append(t_cant_div)

print(n_cant_divs[0] + n_cant_divs[1] - n_cant_divs[2])