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

x = input().split(" ")
a = int(x[0])
b = int(x[1])
c = int(x[2])
d = int(x[3])

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

cd = c*d // fractions.gcd(c,d)
print(cd)

Submission status: Wrong Answer

Solution code:
import math

x = input().split(" ")
a = int(x[0])
b = int(x[1])
c = int(x[2])
d = int(x[3])

c_count = (b//c)-((a-1)//c)
d_count = (b//d)-((a-1)//d)
print(c_count)
print(d_count)

Submission status: Wrong Answer

Solution code:
print(input())

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

a = math.floor(B / C) - math.floor((A-1) / C)
b = math.floor(B / D) - math.floor((A-1) / D)
c = math.floor(B / (lcm(C, D))) - math.floor((A-1) / (lcm(C, D)))

if A == 1:
  a += 1

s = a + b - c

ans = B - (A-1) - s

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

a = math.floor(B / C) - math.floor((A-1) / C)
b = math.floor(B / D) - math.floor((A-1) / D)
c = math.floor(B / (lcm(C, D))) - math.floor((A-1) / (lcm(C, D)))

s = a + b - c

ans = B - (A-1) - s

print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

a = math.floor(B / C) - math.floor((A-1) / C)
b = math.floor(B / D) - math.floor((A-1) / D)
c = math.floor(B / (C*D)) - math.floor((A-1) / (C*D))

s = a + b - c

ans = B - (A-1) - s

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a, b, c, d = [int(i) for i in input().split()]
total = b - a + 1


def pgcd(a, b):
    if b == 0:
        return a
    else:
        r = a % b
        return pgcd(b, r)


def ppcm(a, b):
    if (a == 0) or (b == 0):
        return 0
    else:
        return (a * b) // pgcd(a, b)


def occur(a, b, c):
    r = b - a + 1
    res = r // c
    if not r % c:
        return res
    first = a if not a % c else a + c - a % c
    if a + a % c >= first:
        res += 1
    return res


p = ppcm(c, d)
total -= occur(a, b, c)
total -= occur(a, b, d)
total += occur(a, b, p)

print(total)

Submission status: Wrong Answer

Solution code:
a, b, c, d = [int(i) for i in input().split()]
total = b - a + 1


def pgcd(a, b):
    if b == 0:
        return a
    else:
        r = a % b
        return pgcd(b, r)


def ppcm(a, b):
    if (a == 0) or (b == 0):
        return 0
    else:
        return (a * b) // pgcd(a, b)


def occur(a, b, c):
    r = b - a + 1
    res = r // c
    first = a if not a % c else a + c - a % c
    if a + a % c >= first:
        res += 1
    return res


p = ppcm(c, d)
total -= occur(a, b, c)
total -= occur(a, b, d)
total += occur(a, b, p)

print(total)

Submission status: Wrong Answer

Solution code:
def sa(c,d):
    
    if c>d:
        nn=int(c/d)
        c2=c-d*nn
        if c2<d:
            return c2,d
        else:
            return d,c2
    else :
        nn=int(d/c)
        c2=d-c*nn
        if c2<c:
            return c2,c
        else:
            return c,c2

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

mp=c*d

c1=c+1-1
d1=d+1-1
for i in range(10**18):
    c2,d2=sa(c1,d1)
#    print("c1,d1,c2,d2",c1,d1,c2,d2)    
    if c2<=0:
        break
    c1=c2
    d1=d2

mcm=int(mp/c1)

ac2=int((a-1)/c)
ad2=int((a-1)/d)
am2=int((a-1)/mcm)

bc2=int(b/c)
bd2=int(b/d)
bm2=int(b/mcm)
#print(mcm,ac2,bc2,ad2,bd2,am2,bm2)     

icnt=(bc2-ac2)+(bd2-ad2)-(bm2-am2)
icnt=(b+1-a)-icnt

print(icnt)

Submission status: Wrong Answer

Solution code:
def sa(c,d):
    
    if c>d:
        nn=int(c/d)
        c2=c-d*nn
        if c2<d:
            return c2,d
        else:
            return d,c2
    else :
        nn=int(d/c)
        c2=d-c*nn
        if c2<c:
            return c2,c
        else:
            return c,c2

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

mp=c*d

c1=c+1-1
d1=d+1-1
for i in range(100000000000):
    c2,d2=sa(c1,d1)
#    print("c1,d1,c2,d2",c1,d1,c2,d2)    
    if c2<=0:
        break
    c1=c2
    d1=d2

mcm=int(mp/c1)

ac2=int((a-1)/c)
ad2=int((a-1)/d)
am2=int((a-1)/mcm)

bc2=int(b/c)
bd2=int(b/d)
bm2=int(b/mcm)
#print(mcm,ac2,bc2,ad2,bd2,am2,bm2)     

icnt=(bc2-ac2)+(bd2-ad2)-(bm2-am2)
icnt=(b+1-a)-icnt

print(icnt)

Submission status: Wrong Answer

Solution code:
def sa(c,d):
    
    if c>d:
        nn=int(c/d)
        c2=c-d*nn
        if c2<d:
            return c2,d
        else:
            return d,c2
    else :
        nn=int(d/c)
        c2=d-c*nn
        if c2<c:
            return c2,c
        else:
            return c,c2

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

mp=c*d

c1=c+1-1
d1=d+1-1
for i in range(100000000):
    c2,d2=sa(c1,d1)
#    print("c1,d1,c2,d2",c1,d1,c2,d2)    
    if c2<=0:
        break
    c1=c2
    d1=d2

mcm=int(mp/c1)

ac2=int((a-1)/c)
ad2=int((a-1)/d)
am2=int((a-1)/mcm)

bc2=int(b/c)
bd2=int(b/d)
bm2=int(b/mcm)
#print(mcm,ac2,bc2,ad2,bd2,am2,bm2)     

icnt=(bc2-ac2)+(bd2-ad2)-(bm2-am2)
icnt=(b+1-a)-icnt

print(icnt)

Submission status: Wrong Answer

Solution code:
def sa(c,d):
    
    if c>d:
        c2=c-d
        if c2<d:
            return c2,d
        else:
            return d,c2
    else :
        c2=d-c
        if c2<c:
            return c2,c
        else:
            return c,c2

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

mp=c*d

c1=c+1-1
d1=d+1-1
for i in range(10000000):
    c2,d2=sa(c1,d1)
#    print("c1,d1,c2,d2",c1,d1,c2,d2)    
    if c2<=0:
        break
    c1=c2
    d1=d2

mcm=int(mp/c1)

ac2=int((a-1)/c)
ad2=int((a-1)/d)
am2=int((a-1)/mcm)

bc2=int(b/c)
bd2=int(b/d)
bm2=int(b/mcm)
#print(mcm,ac2,bc2,ad2,bd2,am2,bm2)     

icnt=(bc2-ac2)+(bd2-ad2)-(bm2-am2)
icnt=(b+1-a)-icnt

print(icnt)

Submission status: Wrong Answer

Solution code:
def sa(c,d):
    
    if c>d:
        c2=c-d
        if c2<d:
            return c2,d
        else:
            return d,c2
    else :
        c2=d-c
        if c2<c:
            return c2,c
        else:
            return c,c2

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

mp=c*d

c1=c+1-1
d1=d+1-1
for i in range(10000):
    c2,d2=sa(c1,d1)
#    print("c1,d1,c2,d2",c1,d1,c2,d2)    
    if c2<=0:
        break
    c1=c2
    d1=d2

mcm=int(mp/c1)

ac2=int((a-1)/c)
ad2=int((a-1)/d)
am2=int((a-1)/mcm)

bc2=int(b/c)
bd2=int(b/d)
bm2=int(b/mcm)
#print(mcm,ac2,bc2,ad2,bd2,am2,bm2)     

icnt=(bc2-ac2)+(bd2-ad2)-(bm2-am2)
icnt=(b+1-a)-icnt

print(icnt)

Submission status: Wrong Answer

Solution code:
def sa(c,d):
    
    if c>d:
        c2=c-d
        if c2<d:
            return c2,d
        else:
            return d,c2
    else :
        c2=d-c
        if c2<c:
            return c2,c
        else:
            return c,c2

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

mp=c*d

c1=c+1-1
d1=d+1-1
for i in range(100):
    c2,d2=sa(c1,d1)
#    print("c1,d1,c2,d2",c1,d1,c2,d2)    
    if c2<=0:
        break
    c1=c2
    d1=d2

mcm=int(mp/c1)

ac2=int((a-1)/c)
ad2=int((a-1)/d)
am2=int((a-1)/mcm)

bc2=int(b/c)
bd2=int(b/d)
bm2=int(b/mcm)
#print(mcm,ac2,bc2,ad2,bd2,am2,bm2)     

icnt=(bc2-ac2)+(bd2-ad2)-(bm2-am2)
icnt=(b+1-a)-icnt

print(icnt)

Submission status: Wrong Answer

Solution code:
import numpy as np

def LI():
  return [int(s) for s in input().split()]

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

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

A,B,C,D = LI()

def can_divided(a,b,x):
    ret = (b - a) // x + 1
    #if b % x != 0:
    #  ret+=1
    #if a % x != 0:
    #  ret+=1
    if (a % x) + (x - (b % x)) >= x:
      ret-=1
    
    return ret
  
E = lcm(C,D)

total = can_divided(A,B,C)+can_divided(A,B,D)-can_divided(A,B,E)

print((B-A+1) - total)

Submission status: Wrong Answer

Solution code:
import numpy as np

def LI():
  return [int(s) for s in input().split()]

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

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

A,B,C,D = LI()

def can_divided(a,b,x):
    ret = (b - a) // x + 1
    #if b % x != 0:
    #  ret+=1
    #if a % x != 0:
    #  ret+=1
    return ret
  
E = lcm(C,D)

total = can_divided(A,B,C)+can_divided(A,B,D)-can_divided(A,B,E)

print((B-A+1) - total)

Submission status: Wrong Answer

Solution code:
import numpy as np

def LI():
  return [int(s) for s in input().split()]

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

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

A,B,C,D = LI()

def can_divided(a,b,x):
    ret = (b - a) // x
    if b % x != 0:
      ret+=1
    if a % x != 0:
      ret+=1
    return ret
  
E = lcm(C,D)

total = can_divided(A,B,C)+can_divided(A,B,D)-can_divided(A,B,E)

print((B-A+1) - total)

Submission status: Wrong Answer

Solution code:
x = input().split(" ")
a = int(x[0])
b = int(x[1])
c = int(x[2])
d = int(x[3])

c_count = 0
d_count = 0
cd_count = 0

for i in range(a,b+1):
    if i % (c*d) == 0:
        cd_count += 1
    if i % c == 0:
        c_count += 1
    if i % d == 0:
        d_count += 1

print((b+1-a)-c_count-d_count+cd_count)

Submission status: Wrong Answer

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


def calc(n, div_1, div_2):
    cnt = 0
    cnt += n // div_1
    cnt += n // div_2
    cnt -= int(n / (div_1 * div_2 // gcd(div_1, div_2)))
    return n - cnt


print(calc(b, c, d) - calc(a-1, c, d))

Submission status: Wrong Answer

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


def calc(n, div_1, div_2):
    cnt = 0
    cnt += n // div_1
    cnt += n // div_2
    cnt -= int(n / (div_1 * div_2 / gcd(div_1, div_2)))
    return n - cnt


print(calc(b, c, d) - calc(a-1, c, d))

Submission status: Wrong Answer

Solution code:
# わからなかった

Submission status: Wrong Answer

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

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

def div_count(div):
  #return floor(B/div) - ceil(A/div) + 1
  return B//div - A//div + 1

div_c = div_count(C)
div_d = div_count(D)
lcm = C * D // gcd(C, D)
div_cd = div_count(lcm)

print((B - A + 1) - (div_c + div_d - div_cd))

Submission status: Wrong Answer

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

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

def div_count(div):
  return floor(B/div) - ceil(A/div) + 1

div_c = div_count(C)
div_d = div_count(D)
div_cd = div_count(C*D//gcd(C, D))

print((B - A + 1) - (div_c + div_d - div_cd))

Submission status: Wrong Answer

Solution code:
import fractions as fc
import math
a,b,c,d=map(int,input().split())
ccnt=(b//c)-math.ceil(a//c)
dcnt=(b//d)-math.ceil(a//d)
e=int(c*d/fc.gcd(c,d))
ecnt=(b//e)-math.ceil(a//e)
ans=(b-a+1)-(ccnt+dcnt-ecnt)
if ans<0:
	ans=0
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions as fc
import math
a,b,c,d=map(int,input().split())
ccnt=(b//c)-math.ceil(a//c)
dcnt=(b//d)-math.ceil(a//d)
e=int(c*d/fc.gcd(c,d))
ecnt=(b//e)-math.ceil(a//e)
ans=(b-a+1)-(ccnt+dcnt-ecnt)
print(ans)

Submission status: Wrong Answer

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

    A,B,C,D = map(int,input().split())
    minus = B-A+1
    print(minus-(minus//C+minus//D-(minus//(lcm(C,D)))))
 
if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

    A,B,C,D = map(int,input().split())
    minus = B-A
    print(minus-(minus//C+minus//D-(minus//(lcm(C,D)))))
 
if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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

    g = lcm(c,d)
    res = 0
    cmod = b//c - a//c
    dmod = b//d - a//d
    cdmod = b//g - a//g
    print(b-a+1-cmod-dmod+cdmod)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)

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

    g = lcm(c,d)
    res = 0
    cmod = b//c - (a//c+1) + 1
    dmod = b//d - (a//d+1) + 1
    cdmod = b//g - (a//g+1) + 1
    print(b-a+1-cmod-dmod+cdmod)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from math import ceil

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

def num(l,r,n):
    return r//n-ceil(l/n)+1

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

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

Submission status: Wrong Answer

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

def div(x,y):
  return y//x

def div2(x):
  return div(x,b)-div(x,a-1)
  
print(b-a+1-div2(c)-div2(d)+div2(c*d))

Submission status: Wrong Answer

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

def div(x,y):
  return y//x

def div2(x):
  return div(x,b)-div(x,a)
  
print(b-a+1-div2(c)-div2(d)+div2(c*d))

Submission status: Wrong Answer

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

def div(x):
  a_mod=a%x
  b_mod=b%x
  if b-a>=x and b_mod>=a_mod and a_mod!=0:
    return (b-a)//x
  else:
    return (b-a)//x+1
  
print(b-a+1-div(c)-div(d)+div(c*d))

Submission status: Wrong Answer

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

def div(x):
  a_mod=a%x
  b_mod=b%x
  if b-a>x and b_mod>=a_mod and a_mod!=0:
    return (b-a)//x
  else:
    return (b-a)//x+1
  
print(b-a+1-div(c)-div(d)+div(c*d))

Submission status: Wrong Answer

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

def div(x):
  a_mod=a%x
  b_mod=b%x
  if a_mod<=b_mod and a_mod!=0:
    return (b-a)//x-1
  else:
    return (b-a)//x+1
  
print(b-a+1-div(c)-div(d)+div(c*d))

Submission status: Wrong Answer

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

def div(x):
  a_mod=a%x
  b_mod=b%x
  if -a_mod+b_mod==0:
    return (b-a)//x-1
  elif a_mod<b_mod and a_mod!=0 and b_mod!=0:
    return (b-a)//x
  else:
    return (b-a)//x+1
  
print(b-a+1-div(c)-div(d)+div(c*d))

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int,input().split())
def gcd(a,b):
    if b>a:
        b,a=a,b
    if b==0:
        return a
    else:
        return gcd(b,a%b)


def warikiri(n,c,d):
    koubai=(c*d)//gcd(c,d)
    return n-math.floor(n/d)-math.floor(n/c)+math.floor(n/koubai)
print(warikiri(b,c,d)-warikiri(a-1,c,d))

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int,input().split())
def warikiri(n,d):
    return math.floor(n/d)
def gcd(a,b):
    if b>a:
        b,a=a,b
    if b==0:
        return a
    else:
        return gcd(b,a%b)
koubai=(c*d)//gcd(c,d)
print((b-a+1) - ((warikiri(b,d)-warikiri(a-1,d)) + (warikiri(b,c)-warikiri(a-1,c)) - (warikiri(b,koubai)-warikiri(a-1,koubai))))

Submission status: Wrong Answer

Solution code:
import fractions


def func(a, b, div):
    if (a/div).is_integer(): c_1 = int(a/div)
    else: c_1 = a // div + 1
    c_2 = b // div
    return int(c_2 - c_1 + 1)


a, b, c, d = (int(x) for x in input().split())
print(int((b - a + 1) - func(a, b, c) - func(a, b, d) + func(a, b, c*d//fractions.gcd(c, d))))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
 
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a
 
 
 
def lcm(a, b):
    return a * b // (gcd(a, b))
 
 
 
def main():
    A, B, C, D = map(int, input().split())
    Aone = A - 1
    CDlcm = lcm(C, D)
 
    Bc = B // C
    Bd = B // D
    Blcm = B // CDlcm
    Bdec = B - Bc - Bd + Blcm
 
#    print(Bc,Bd,Blcm)
 
    Ac = Aone // C
    Ad = Aone // D
    Alcm = Aone // CDlcm
    Adec = Aone - Ac - Ad + Alcm
 
#    print(Ac,Ad,Alcm)
 
    print(Bdec - Adec)

Submission status: Wrong Answer

Solution code:
import sys

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



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



def main():
    A, B, C, D = map(int, input().split())
    Aone = A - 1
    CDlcm = lcm(C, D)

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / CDlcm)
    Bdec = B - Bc - Bd + Blcm

#    print(Bc,Bd,Blcm)

    Ac = int(Aone / C)
    Ad = int(Aone / D)
    Alcm = int(Aone / CDlcm)
    Adec = Aone - Ac - Ad + Alcm

#    print(Ac,Ad,Alcm)

    print(Bdec - Adec)


main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import fractions

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

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


def main():
    A, B, C, D = list(map(int, input().split()))
    Aone = A - 1
    CDlcm = lcm(C, D)

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / CDlcm)
    Bdec = B - Bc - Bd + Blcm

#    print(Bc,Bd,Blcm)

    Ac = int(Aone / C)
    Ad = int(Aone / D)
    Alcm = int(Aone / CDlcm)
    Adec = Aone - Ac - Ad + Alcm

#    print(Ac,Ad,Alcm)

    print(Bdec - Adec)


main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    Aone = A - 1
    lcm = int(C * D // fractions.gcd(C, D))

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / lcm)
    Bdec = B - Bc - Bd + Blcm

#    print(Bc,Bd,Blcm)

    Ac = int(Aone / C)
    Ad = int(Aone / D)
    Alcm = int(Aone / lcm)
    Adec = Aone - Ac - Ad + Alcm

#    print(Ac,Ad,Alcm)

    print(Bdec - Adec)


main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    Aone = A - 1
    lcm = int(C / fractions.gcd(C, D) * D)

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / lcm)
    Bdec = B - Bc - Bd + Blcm

#    print(Bc,Bd,Blcm)

    Ac = int(Aone / C)
    Ad = int(Aone / D)
    Alcm = int(Aone / lcm)
    Adec = Aone - Ac - Ad + Alcm

#    print(Ac,Ad,Alcm)

    print(Bdec - Adec)


main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    Aone = A - 1
    lcm = int(C / fractions.gcd(C, D) * D)

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / lcm)
    Bdec = Bc + Bd - Blcm

#    print(Bc,Bd,Blcm)

    Ac = int(Aone / C)
    Ad = int(Aone / D)
    Alcm = int(Aone / lcm)
    Adec = Ac + Ad - Alcm

#    print(Ac,Ad,Alcm)

    print(B - A + 1 - (Bdec - Adec))


main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    Aone = A - 1
    lcm = int(C * D / fractions.gcd(C, D))

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / lcm)
    Bdec = Bc + Bd - Blcm

#    print(Bc,Bd,Blcm)

    Ac = int(Aone / C)
    Ad = int(Aone / D)
    Alcm = int(Aone / lcm)
    Adec = Ac + Ad - Alcm

#    print(Ac,Ad,Alcm)

    print(B - A + 1 - (Bdec - Adec))


main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    Aone = A - 1
    lcm = C * D / fractions.gcd(C, D)

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / lcm)
    Bdec = Bc + Bd - Blcm

#    print(Bc,Bd,Blcm)

    Ac = int(Aone / C)
    Ad = int(Aone / D)
    Alcm = int(Aone / lcm)
    Adec = Ac + Ad - Alcm

#    print(Ac,Ad,Alcm)

    print(B - A + 1 - (Bdec - Adec))


main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    A -= 1
    lcm = C * D / fractions.gcd(C, D)

    Bc = int(B / C)
    Bd = int(B / D)
    Blcm = int(B / lcm)
    Bdec = B - (Bc + Bd - Blcm)

    Ac = int(A / C)
    Ad = int(A / D)
    Alcm = int(A / lcm)
    Adec = A - (Ac + Ad - Alcm)

    print(Bdec - Adec)


main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    A -= 1
    lcm = C * D / fractions.gcd(C, D)

    Bc = int(B // C)
    Bd = int(B // D)
    Blcm = int(B // lcm)
    Bdec = B - (Bc + Bd - Blcm)

    Ac = int(A // C)
    Ad = int(A // D)
    Alcm = int(A // lcm)
    Adec = A - (Ac + Ad - Alcm)

    print(Bdec - Adec)


main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import fractions

def main():
    A, B, C, D = list(map(int, input().split()))
    lcm = C * D / fractions.gcd(C, D)

    Ac = int(A/C)
    if A % C == 0:
        Ac-=1

    Bc = int(B/C)
    cnum = Bc - Ac

    Ad = int(A/D)
    if A % D == 0:
        Ad-=1

    Bd = int(B/D)
    dnum =Bd - Ad

    Alcm = int(A/lcm)
    if A % lcm == 0:
        Alcm-=1

    Blcm = int(B/lcm)
    lcmnum = Blcm - Alcm

    print(B - A + 1 - (cnum + dnum - lcmnum))

main()

Submission status: Wrong Answer

Solution code:
w,h,x,y = map(int, input().split())
if abs(2*x-w) == abs(2*y-h):
    print(h*w/2,1)
else:
    print(w*h/2,0)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
def gcd(a,b):
    if a<b:
        return gcd(b,a)
    else:
        if b==0:
            return a
        else:
            return gcd(b, a%b)
cd= c*d//gcd(c,d)

ans = b-a+1-((b-a+1)//c + (b-a+1)//d - (b-a+1)//cd)
acr=a%c
bcr=b%c
if bcr < acr:
    ans-=1
elif bcr==0 and acr==0:
    ans-=1
adr=a%d
bdr=b%d
if bdr < adr:
    ans-=1
elif bdr==0 and adr==0:
    ans-=1
    
acdr=a%cd
bcdr=b%cd
if bcdr < acdr:
    ans+=1
elif bcdr==0 and acdr==0:
    ans-=1

if c==1 or d==1:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
def gcd(a,b):
    if a<b:
        return gcd(b,a)
    else:
        if b==0:
            return a
        else:
            return gcd(b, a%b)
cd= c*d//gcd(c,d)

ans = b-a+1-((b-a+1)//c + (b-a+1)//d - (b-a+1)//cd)
acr=a%c
bcr=b%c
if bcr <= acr:
    ans-=1
adr=a%d
bdr=b%d
if bdr <= adr:
    ans-=1
acdr=a%cd
bcdr=b%cd
if bcdr <= acdr:
    ans+=1
if c==1 or d==1:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
def gcd(a,b):
    if a<b:
        return gcd(b,a)
    else:
        if b==0:
            return a
        else:
            return gcd(b, a%b)
cd= c*d//gcd(c,d)

ans = b-a+1-((b-a+1)//c + (b-a+1)//d - (b-a+1)//cd)
acr=a%c
bcr=b%c
if bcr < acr:
    ans-=1
adr=a%d
bdr=b%d
if bdr < adr:
    ans-=1
acdr=a%cd
bcdr=b%cd
if bcdr < acdr:
    ans+=1
if c==1 or d==1:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
def gcd(a,b):
    if a<b:
        return gcd(b,a)
    else:
        if b==0:
            return a
        else:
            return gcd(b, a%b)
cd= c*d//gcd(c,d)

ans = b-a+1-((b-a+1)//c + (b-a+1)//d - (b-a+1)//cd)
acr=a%c
bcr=b%c
if bcr < acr:
    ans-=1
adr=a%d
bdr=b%d
if bdr < adr:
    ans-=1
acdr=a%cd
bcdr=b%cd
if bcdr < acdr:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int, input().split())
ci = (b//c) - (a//c)
di = (b//d) - (a//d)
e = c * d // gcd(c, d)
cdi = (b//e) - (a//e)
print(b-(a-1)-(ci+di-cdi))

Submission status: Wrong Answer

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


a,b,c,d = map(int,input().split())
count = 0
i = b//c - a//c 
if(a%c == 0):
  i += 1
j = b//d - a//d
if(a%d == 0):
  j += 1
k = b//lcm(c,d) - a//lcm(c,d)

print(b-a+1-(i+j-k))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

# CとDの最大公約数
E = lcm(C, D)

F = 0
F += B // C + B // D - B // E
F -= (A - 1) // C + (A - 1) // D + (A - 1) // E

print(B - A + 1 - F)

Submission status: Wrong Answer

Solution code:
from math import ceil
from fractions import gcd


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

def num(l,r,x):
    return r//x-ceil(l/x)+1

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

cn=num(a,b,c)
dn=num(a,b,d)
cdn=num(a,b,lcm(min(c,d),max(c,d)))

ans=(b-a+1)-(cn+dn-cdn)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
a,b,c,d=map(int,input().split())
def gcd(x,y):
    while y%x!=0:
        a=x
        x=y%x
        y=a
    return x

def num(l,r,x):
    return r//x-ceil(l/x)+1

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

cn=num(a,b,c)
dn=num(a,b,d)
cdn=num(a,b,lcm(min(c,d),max(c,d)))

ans=(b-a+1)-(cn+dn-cdn)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil
a,b,c,d=map(int,input().split())
def gcd(x,y):
    while y%x!=0:
        a=x
        x=y%x
        y=a
    return x

def num(l,r,x):
    return r//x-ceil(l/x)+1

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

ans=0
ans+=(b-a+1)-(num(a,b,c)+num(a,b,d)-num(a,b,lcm(min(c,d),max(c,d))))
print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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


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


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


def interval(a, b, c):
    a1 = (a-1)//c
    b1 = b//c
    return b1 - a1


l = lcm(c, d)

print(int(b-a+1 - (interval(a, b, c) + interval(a, b, d) - interval(a, b, l))))

Submission status: Wrong Answer

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


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


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


def interval(a, b, c):
    a1 = a//c if a%c == 0 else a//c + 1
    b1 = b//c+1
    return b1 - a1


l = lcm(c, d)

print(int(b-a+1 - (interval(a, b, c) + interval(a, b, d) - interval(a, b, l))))

Submission status: Wrong Answer

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


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


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

l = lcm(a, b)

a1 = a/c if a%c == 0 else a//c + 1
a2 = a/d if a%d == 0 else a//d + 1
b1 = b/c if b%c == 0 else b//c + 1
b2 = b/d if b%d == 0 else b//d + 1
a3 = a/l if a%l == 0 else a//l + 1
b3 = b/l if b%l == 0 else b//l + 1

print(int(b-a+1 - ((b1 - a1) + (b2 - a2) - (b3 - a3))))

Submission status: Wrong Answer

Solution code:
import fractions

a, b, c, d = [int(i) for i in input().split()]
b_s = (b - b//c - b//d + b//(c * d * fractions.gcd(c, d)))
a -= 1
a_s = (a - a//c - a//d + a//(c * d * fractions.gcd(c, d)))
ans = b_s - a_s
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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


def f(n):
    x = n//c
    x += n//d
    lcm = c*d/gcd(c, d)
    x -= n//lcm
    return n-x


print(round(f(b)-f(a-1)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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


def f(n):
    x = n//c
    x += n//d
    lcm = c*d/gcd(c, d)
    x -= n//lcm
    return n-x


print(f(b)-f(a-1))

Submission status: Wrong Answer

Solution code:
import math
a, b, c, d = [int(ch) for ch in input().strip().split()]
print(0)

Submission status: Wrong Answer

Solution code:
def euclid(x, y):
    x_1 = x
    y_1 = y
    a = x_1%y_1
    while a != 0:
        x_1 = y_1
        y_1 = a
        a = x_1%y_1
    return (x * y) / y_1

def dif(x, C, D):
    return x - (x//C) - (x//D) + (x//(euclid(C, D)))

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

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
# 最小公倍数を返す
def euclid(x, y):
    x_1 = x
    y_1 = y
    a = x_1%y_1
    while a != 0:
        x_1 = y_1
        y_1 = a
        a = x_1%y_1
    return (x * y) / y_1

# x以下のCとDで割り切れる数を返す
def dif(x, C, D):
    return x - (x//C) - (x//D) + (x//(euclid(C, D)))

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

if __name__ == '__main__':
    print(int(main()))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d=map(int,input().split())
def lcm(n,m):
    return (n*m)//gcd(n,m)
cntb=b-(b//c)-(b//d)+(b//lcm(c,d))
cnta=a-1-(a-1)//c-((a-1)//d)+((a-1)//lcm(c,d))
ans=cntb+cnta
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

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

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

def count_prime(x):
    return (b // x) - ((a-1) // x) + 1

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

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

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

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

def count_prime(x):
    return (b // x) - math.ceil(a / x) + 1

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

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split())
e = int((b-a)/c)
f = int((b-a)/d)
r = e+f
s = a+min(c,d)
m = max(c,d)
t = min(c,d)
o = (int(a/m)+1)*m
while(o < b):
    o += m
    if (o%t == 0):
        r -= 1

print((b-a)-(r))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import math
from fractions import gcd
def lcm(a, b):
    return a*b // gcd(a, b)
A, B, C, D = map(int, input().split())
CD = math.ceil(lcm(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:
import fractions

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

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

c_divide = (B // C) - ((A - 1) // C)
d_divide = (B // D) - ((A - 1) // D)
cd_divide = (B // lcm(C, D)) - (A // lcm(C, D))
ans = (B - A + 1) - c_divide - d_divide + cd_divide
print(max(ans, 0))