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:
a,b,c,d = map(int,input().split())
x = b//c - -(-a//c) + 1
y = b//d - -(-a//d) + 1
z = b//(c*d) - -(-a//(c*d)) + 1

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

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = map(int,input().split())
count = 0
E = C*D/fractions.gcd(C,D)
#print(math.gcd(C,D))
def a(A,B,C):
  key = B//C - (A-1)//C
  return key
   

	
count = a(A,B,C)  + a(A,B,D) - a(A,B,E)

print(B-A-int(count) + 1)

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = map(int,input().split())
count = 0
E = C*D/fractions.gcd(C,D)
#print(math.gcd(C,D))
def a(A,B,C):
  key = B//C - (A-1)//C
  return key
   

	
count = a(A,B,C)  + a(A,B,D)-a(A,B,E)

print(B-A-int(count)+1)

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = map(int,input().split())
count = 0
E = C*D/fractions.gcd(C,D)
#print(math.gcd(C,D))
def a(A,B,C):
  key = A//C +1
  if B < C:
    return 0
  else:
    return ((B-key*C)//C )+ 1
   

	
count = a(A,B,C)  + a(A,B,D)-a(A,B,E)
if A==B:
	print(0)
else:
	print(B-A-int(count)+1)

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = map(int,input().split())
count = 0
E = C*D/fractions.gcd(C,D)
#print(math.gcd(C,D))
def a(A,B,C):
  key = A//C +1
  if B < C:
    return 0
  else:
    return ((B-key*C)//C )+ 1
   

	
count = a(A,B,C)  + a(A,B,D)-a(A,B,E)

print(B-A-int(count)+1)

Submission status: Wrong Answer

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

from fractions import gcd


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

C_ = (B // C) - ((A - 1) // C)

D_ = (B // D) - ((A - 1) // D)

# 最大公約数
CD = gcd(C, D)

# 最小公倍数
CD = (C * D) / CD

CD_ = (B // CD) - ((A - 1) // CD)

total_num = B - (A - 1)

ans = total_num - C_ - D_ + CD_

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math

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

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

def lcm_(x,y):
    return (x * y) // gcd_(x, y)

def f(x, y):
    return math.floor(x / y)

lcm = lcm_(C, D)
ret1 = A - 1 - f(A - 1, C) - f(A - 1, D) + f(A - 1, lcm)
ret2 = B - f(B, C) - f(B, D) + f(B, lcm)
ans = ret2 - ret1
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

def lcm_(x,y):
    return (x * y) // gcd_(x, y)

def f(x):
    if A % x:
        a = A + (x - A % x)
    else:
        a = A
    if B - a >= 0:
        return math.ceil((B - a + 1) / x)
    else:
        return 0
    
ans = (B - A + 1) - f(C) - f(D) + f(lcm_(C, D))
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int, input().split())
def f(p):
  if a % p ==0:
    return(b//p - a//p + 1)
  else:
    return(b//p - a//p)
  
print(b-a+1 - (f(c)+f(d) - f(c*d/gcd(c,d))))

Submission status: Wrong Answer

Solution code:
import fractions
#import math

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

# cで割り切れる、またはdで割り切れるものから、両方で割り切れるものを引く

# cで割り切れる; i
i = b//c - a//c

# dで割り切れる; j
j = b//d - a//d

#両方で割り切れる; k
lcm = a*b / (fractions.gcd(a,b))
#lcm = a*b / (math.gcd(a,b))
k = b//lcm - a//lcm

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd


def lcm(c, d):
    return (c * d) // gcd(c, d)


def main():
    a, b, c, d = map(int, input().split())
    c_num = (b//c-(a-1)//c)
    d_num = (b//d-(a-1)//d)
    cd_num = (b//lcm(c, d)-a//lcm(c, d))
    ans = b-a+1-c_num-d_num+cd_num
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

x=b-a+1
A=a-1
bclcm=d*c/fractions.gcd(c,d)
y=(b//c)+(b//d)-(b//(bclcm))
z=(A//c)+(A//d)-(A//(bclcm))

ans=x-y+z

print(int(ans))

Submission status: Wrong Answer

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

x=b-a+1

y=(b//c)+(b//d)-(b//(c*d))
z=(a//c)+(a//d)-(a//(c*d))

ans=x-y+z
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

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

a = int(B / C) - int((A-1) / C)
b = int(B / D) - int((A-1) / D) 
c = C * D / fractions.gcd(C, D)
d = int(B / c) - int((A-1) / c)

Ans = (B - A + 1) - a - b + d 
print(Ans)

Submission status: Wrong Answer

Solution code:
import math

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

a = int(B / C) - int((A-1) / C)
b = int(B / D) - int((A-1) / D) 
c = C * D 
d = int(B / c) - int((A-1) / c)

Ans = (B - A + 1) - a - b + d 
print(Ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import fractions

gcd = fractions.gcd

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

    c_baisuu = int(b/c)-int((a-1)/c)
    d_baisuu = int(b/d)-int((a-1)/d)
    cd = int(c * d / gcd(c, d))
    cd_baisuu = int(b/(cd))-int((a-1)/(cd))
    zenbu = b-a+1
    print(zenbu-(c_baisuu+d_baisuu-cd_baisuu))
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import fractions

gcd = fractions.gcd

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

    c_baisuu = int(b/c)-int((a-1)/c)
    d_baisuu = int(b/d)-int((a-1)/d)
    cd = c * d / gcd(c, d)
    cd_baisuu = int(b/(cd))-int((a-1)/(cd))
    zenbu = b-a+1
    print(zenbu-(c_baisuu+d_baisuu-cd_baisuu))
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    c_baisuu = int(b/c)-int((a-1)/c)
    d_baisuu = int(b/d)-int((a-1)/d)
    cd_baisuu = int(b/(c*d))-int((a-1)/(c*d))
    zenbu = b-a+1
    print(zenbu-(c_baisuu+d_baisuu-cd_baisuu))
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import fractions as math

def main():
    a,b,c,d = map(int, input().split())
    al = b-a+1
    x = al // c
    y = al // d
    z = al // (c/math.gcd(c,d)*d)
    an = x+y-z
    #print(al, an)
    print(int(al-an))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    a,b,c,d = map(int, input().split())
    al = b-a+1
    x = al / c
    y = al / d
    z = al / (c*d)
    an = round(x+y-z)
    #print(al, an)
    print(int(al-an))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
  while y:
    x,y = y,x%y
  return x

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
import fractions
e = fractions.gcd(a,b)
cnt = d//a + d//b + c//e - c//a -c//b - d//e
print(d-c-cnt)

Submission status: Wrong Answer

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

from fractions import gcd
lcm = c * d / gcd(c, d)
print(lcm)

num = 0
for i in range(a, b+1):
    if i % c == 0:
        num += 1
    if i % d == 0:
        num += 1
    if i % lcm == 0:
        num -= 1

print(b - a + 1 - num)

Submission status: Wrong Answer

Solution code:
a, b, c, d=map(int, input().split())
counter=0
for x in range(a, b):
   if x % c > 0:
      if x % d > 0:
         counter=counter+1

print(counter)

Submission status: Wrong Answer

Solution code:

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

    sss = b//c - (a-1)//c
    ssss = b//d - (a-1)//d
    if d % c == 0:
        di = c
    elif c % d == 0:
        di = d
    elif ((d*c)/2) % c == 0 and ((d*c)/2) % d == 0:
        di = d*c//2
    else:
        di = c*d
    sssss = b // di - (a - 1) // di if di != 0 else 0
    print((b-a+1) - (sss+ssss-sssss))


if __name__ == '__main__':
    main2()

Submission status: Wrong Answer

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

    sss = b//c - (a-1)//c
    ssss = b//d - (a-1)//d
    if d % c == 0:
        di = c
    elif c % d == 0:
        di = d
    else:
        di = c*d
    sssss = b // di - (a - 1) // di if di != 0 else 0
    print((b-a+1) - (sss+ssss-sssss))


if __name__ == '__main__':
    main2()

Submission status: Wrong Answer

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

    sss = b//c - (a-1)//c
    ssss = b//d - (a-1)//d
    di = 0
    for i in range(d, b, d):
        if i % c == 0:
            di = i
            break
    sssss = b // di - (a - 1) // di if di != 0 else 0
    print((b-a+1) - (sss+ssss-sssss))


if __name__ == '__main__':
    main2()

Submission status: Wrong Answer

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

    sss = b//c - (a-1)//c
    ssss = b//d - (a-1)//d
    di = 0
    for i in range(d, a, d):
        if i % d == 0:
            di = i
            break
    sssss = b // di - (a - 1) // di if di != 0 else 0
    print((b-a+1) - (sss+ssss-sssss))


if __name__ == '__main__':
    main2()

Submission status: Wrong Answer

Solution code:
# cまたはdで割り切れるものを計算して、b-a+1の全体から引く
from fractions import gcd

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

def c_d_koubai(x, y, w, z):
    c_d_koubai =  w * z / gcd(w, z)

    # 最初の公倍数が先頭から何番目に位置するか（インデックス、先頭が0として）
    a_amari = x % c_d_koubai
    if a_amari == 0:
        koubai_sentou = 0
    else:
        koubai_sentou = c_d_koubai - a_amari 
    
    # bは先頭から何番目か（インデックス）
    b_number = y - x
    
    # a~bの間に公倍数がない
    if b_number < koubai_sentou:
        koubai_num = 0
    else:
        # a~bの間に公倍数が何個あるか
        koubai_num = (b_number-koubai_sentou) // c_d_koubai + 1
    return koubai_num

def c_d_only_bai(x, y, w):
    c_d_amari = x % w
    if c_d_amari == 0:
        c_d_sentou = 0
    else:
        c_d_sentou= w - x%w
    c_d_number = y - x

    if c_d_number < c_d_sentou:
        c_d_num = 0
    else:
        c_d_num = (c_d_number-c_d_sentou) // w + 1
    return c_d_num


koubai = c_d_koubai(a, b, c, d)
c_koubai = c_d_only_bai(a, b, c)
d_koubai = c_d_only_bai(a, b, d)

print(int(b-a+1-(c_koubai+d_koubai-koubai)))

Submission status: Wrong Answer

Solution code:
# cまたはdで割り切れるものを計算して、b-a+1の全体から引く
from fractions import gcd

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

def c_d_koubai(x, y, w, z):
    c_d_koubai =  w * z / gcd(w, z)

    # 最初の公倍数が先頭から何番目に位置するか（インデックス、先頭が0として）
    a_amari = x % c_d_koubai
    if a_amari == 0:
        koubai_sentou = 0
    else:
        koubai_sentou = c_d_koubai - a_amari 
    
    # bは先頭から何番目か（インデックス）
    b_number = y - x
    
    # a~bの間に公倍数がない
    if b_number < koubai_sentou:
        koubai_num = 0
    else:
        # a~bの間に公倍数が何個あるか
        koubai_num = (b_number-koubai_sentou) // c_d_koubai + 1
    return koubai_num

def c_d_only_bai(x, y, w):
    c_d_amari = x % w
    if c_d_amari == 0:
        c_d_sentou = 0
    else:
        c_d_sentou= w - x%w
    c_d_number = y - x

    if c_d_number < c_d_sentou:
        c_d_num = 0
    else:
        c_d_num = (c_d_number-c_d_sentou) // w + 1
    return c_d_num


koubai = c_d_koubai(a, b, c, d)
c_koubai = c_d_only_bai(a, b, c)
d_koubai = c_d_only_bai(a, b, d)

print(b-a+1-(c_koubai+d_koubai-koubai))

Submission status: Wrong Answer

Solution code:
import fractions

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

print(b-a-x-y+z if (b-a-x-y+z)>0 else 0)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

Submission status: Wrong Answer

Solution code:
import fractions

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

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

Submission status: Wrong Answer

Solution code:
import fractions

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

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

Submission status: Wrong Answer

Solution code:
import fractions

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

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

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
ans = b - a + 1
x = b // c - a // c
if a % c == 0:
    x += 1
x += b // d - a // d
if a % d == 0:
    x += 1
x -= b // (c * d) - a // (c * d)
if a % (c * d) == 0:
    x -= 1
ans -= x
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from decimal import Decimal

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

A, B, C, D = map(int, input().split())
count = 0
BCcount = B // C
BDcount = B // D
ACcount = (A - 1) // C
ADcount = (A - 1) // D
l = C * D // gcd(C, D)
BCDcount = B // l
print(BCDcount)
ACDcount = (A - 1) // l
print(ACDcount)
Bcount = Decimal(B - (BCcount + BDcount - BCDcount))
Acount = Decimal((A - 1) - (ACcount + ADcount - ACDcount))
print(Decimal(Bcount - Acount))

Submission status: Wrong Answer

Solution code:
import fractions

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

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

gcd_cd = lcm(c,d)

a_c_numbers = a//c
if a % c == 0:
    a_c_numbers -= 1
a_d_numbers = a//d
if a % d == 0:
    a_d_numbers -= 1

a_numbers = a_c_numbers + a_d_numbers

b_c_numbers = b//c
b_d_numbers = b//d
b_numbers = b_c_numbers + b_d_numbers

gcd_cd_numbers = b//gcd_cd - a//gcd_cd

# print(a_c_numbers,a_d_numbers)
# print(b_c_numbers,b_d_numbers)
# print(gcd_cd_numbers)
# print(b_numbers - a_numbers - gcd_cd_numbers)
ans = b - a + 1 - (b_numbers - a_numbers - gcd_cd_numbers)

if ans > 0:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

gcd_cd = lcm(c,d)

a_c_numbers = a//c
if a % c == 0:
    a_c_numbers -= 1
a_d_numbers = a//d
if a % d == 0:
    a_d_numbers -= 1

a_numbers = a_c_numbers + a_d_numbers

b_c_numbers = b//c
b_d_numbers = b//d
b_numbers = b_c_numbers + b_d_numbers

gcd_cd_numbers = b//gcd_cd - a//gcd_cd

# print(a_c_numbers,a_d_numbers)
# print(b_c_numbers,b_d_numbers)
# print(gcd_cd_numbers)
# print(b_numbers - a_numbers - gcd_cd_numbers)
print(b - a + 1 - (b_numbers - a_numbers - gcd_cd_numbers))

Submission status: Wrong Answer

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

total = B - A + 1
num_C = B // C - (A-1)//C
num_D = B // D - (A-1)//D
num_CD = B//(C*D) - (A-1)//(C*D)

ans = total - (num_C + num_D - num_CD)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)
a,b,c,d = map(int,input().split())
all = b - a + 1
if c == 1 or d == 1:
    print(0)
    exit()

cd = lcm(c, d)

cs = b//c - a//c + 1
ds = b//d - a//d + 1
cds = b//cd - a//cd + 1

print(all - cs - ds + cds)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

a,b,c,d = map(int,input().split())
all = b - a + 1
if c == 1 or d == 1:
    print(0)
    exit()

cd = lcm(a, b)

cs = b//c - a//c + 1
ds = b//d - a//d + 1
cds = b//cd - a//cd + 1

print(all - cs - ds + cds)

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


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


def main():
    input = stdin.buffer.readline
    a, b, c, d = map(int, input().split())
    g = gcd(c, d)
    l = (c * d) // g
    ans = 0
    ans += l - (l // c + l // d - 1)
    ans *= (b - a) // l
    tmp = (b - a) % l
    ans += tmp - (tmp // c + tmp // d)
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
import math

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

A, B, C, D = map(int, input().split())
count = 0
BCcount = math.floor(B / C)
BDcount = math.floor(B / D)
ACcount = math.floor((A - 1) / C)
ADcount = math.floor((A - 1) / D)
l = C * D / gcd(C, D)
BCDcount = math.floor(B / l)
ACDcount = math.floor((A - 1) / l)
Bcount = B - (BCcount + BDcount - BCDcount) 
Acount = (A - 1) - (ACcount + ADcount - ACDcount)
print(Bcount - Acount)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
if a != 0:
    xc = int((a-1)/c)
    yc = int(b/c)
    xd = int((a-1)/d)
    yd = int(b/d)
    xcd = int((a - 1) / (c * d))
    ycd = int(b / (c * d))
else:
    xc = int((a)/c)
    yc = int(b/c)
    xd = int((a)/d)
    yd = int(b/d)
    xcd = int((a) / (c * d))
    ycd = int(b / (c * d))
print(b - a + 1 -((yc - xc) + (yd - xd) - (ycd - xcd)))

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

count = 0
div_C = B // C - math.ceil(A / C) + 1
div_D = B // D - math.ceil(A / D) + 1
div_C_D = B // lcm - math.ceil(A / lcm) + 1


print(B - A + 1 - div_C - div_D + div_C_D)

Submission status: Wrong Answer

Solution code:
# 最小公倍数(mathは3.5以降) fractions
# 参考　https://note.nkmk.me/python-gcd-lcm/

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y) # 「//」はフロートにせずにintにする
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

# 初期入力
from functools import reduce
import fractions #(2020-0405  fractions→math)
import sys
input = sys.stdin.readline
A,B,C,D = (int(x) for x in input().split())

c_multi_B =B // C #Cの倍数
d_multi_B =B // D #Dの倍数
least_common_multi =lcm(C,D)
cd_common_multi_B =B //least_common_multi

c_multi_A =(A -1) // C #Cの倍数
d_multi_A =(A -1) // D #Dの倍数
least_common_multi =lcm(C,D)
cd_common_multi_A =A //least_common_multi

#A以上、B以下
all =B -A +1

ans =all - (c_multi_B -(c_multi_A )) -(d_multi_B -(d_multi_A )) + cd_common_multi_B -cd_common_multi_A
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

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


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


LCM_CD = lcm(C, D)
C_Count = B // C - A // C
D_Count = B // D - A // D
CD_Count = B // (LCM_CD) - A // (LCM_CD)

print(B - A + 1 - C_Count - D_Count + CD_Count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# import sys
# from functools import lru_cache, cmp_to_key
# from heapq import merge, heapify, heappop, heappush
# from math import *
# # import math
# from collections import defaultdict as dd, deque, Counter as C
# from itertools import combinations as comb, permutations as perm
# from bisect import bisect_left as bl, bisect_right as br, bisect
# from time import perf_counter
# from fractions import Fraction
# # sys.setrecursionlimit(int(pow(10, 2)))
# # sys.stdin = open("input.txt", "r")
# # sys.stdout = open("output.txt", "w")
# mod = int(pow(10, 9) + 7)
# mod2 = 998244353
# def data(): return sys.stdin.readline().strip()
# def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
# def l(): return list(sp())
# def sl(): return list(ssp())
# def sp(): return map(int, data().split())
# def ssp(): return map(str, data().split())
# def l1d(n, val=0): return [val for i in range(n)]
# def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# # @lru_cache(None)

# # def seive():
# #     prime=[1 for i in range(10**6+1)]
# #     prime[0]=0
# #     prime[1]=0
# #     for i in range(10**6+1):
# #         if(prime[i]):
# #             for j in range(2*i,10**6+1,i):
# #                 prime[j]=0


# a,b,c,d=l()
# ans=0
# # print(a,b,c,d,b//c,a//c)
# ans+=(b//c-a//c+(a%c==0))
# # print(ans)
# ans+=(b//d-a//d+(a%d==0))
# # print(ans)
# lcm=c*d//gcd(c,d)
# ans-=(b//lcm-a//lcm+(a%lcm==0))
# print(b-a+1-ans)
a=input()
print(a)

Submission status: Wrong Answer

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

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

if (c == 1) or (d == 1):
    print(0)
    sys.exit()

c_all  = b//c
d_all  = b//d
cd_all = int(b//(c*d/gcd(c,d)))
count_all = b + cd_all - c_all - d_all

c_a  = (a-1)//c
d_a  = (a-1)//d
cd_a = int((a-1)//(c*d/gcd(c,d)))
count_a = a - 1 + cd_a - c_a - d_a

if c == d:
    print((b - c_all) - (a - 1 - c_a))
else:
    print(count_all - count_a)

Submission status: Wrong Answer

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

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

if (c == 1) or (d == 1):
    print(0)
    sys.exit()

c_all  = b//c
d_all  = b//d
cd_all = int(b//(c*d/gcd(c,d)))
count_all = b + cd_all - c_all - d_all

c_a  = (a-1)//c
d_a  = (a-1)//d
cd_a = int((a-1)//(c*d/gcd(c,d)))
count_a = a - 1 + cd_a - c_a - d_a

if c == d:
    print(b + c_all - a + 1 + c_a)
else:
    print(count_all - count_a)

Submission status: Wrong Answer

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

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

if (c == 1) or (d == 1):
    print(0)
    sys.exit()

c_all  = b//c
d_all  = b//d
cd_all = int(b//(c*d/gcd(c,d)))
count_all = b + cd_all - c_all - d_all

c_a  = (a-1)//c
d_a  = (a-1)//d
cd_a = int((a-1)//(c*d/gcd(c,d)))
count_a = a - 1 + cd_a - c_a - d_a

print(count_all - count_a)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)

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

a, b, c, d = map(int, input().split())
divc = b // c - a // c
if a % c == 0:
    divc += 1
divd = b // d - a // d
if a % d == 0:
    divd += 1
    
lcm = c * d / gcd(c, d)
divlcm = b // lcm - a // lcm
if a % lcm == 0:
    divlcm += 1


div_or = divc + divd - divlcm
print(int(b - a + 1 - div_or))

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = map(int,input().split())
lcm = C * D // fractions.gcd(C,D)
a = A // lcm
b = B // lcm
print(B-A-(b-a))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
cd = c * d
n_c = 0
n_d = 0
n_cd = 0
i = ( a // c  ) + c
while i <= b:
    n_c += 1
    i += c
i = ( a // d) + d
while i <= b:
    n_d += 1
    i += d
i = ( a // cd ) + cd
while i<= b:
    n_cd += 1
    i+=cd
print(b-a+1-(n_c+n_d-n_cd))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
cd = c * d
n_c = 0
n_d = 0
n_cd = 0
i = ( a / c + 1 ) * c
while i <= b:
    n_c += 1
    i *= c
i = ( a / d + 1 ) * d
while i <= b:
    n_d += 1
    i *= c
i = ( a / cd + 1 ) * cd
while i<= b:
    n_cd += 1
    i*=cd
print(b-a+1+n_c+n_d-n_cd)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
line = input().split()
import fractions
lcm = int(int(line[2])*int(line[3]) / fractions.gcd(int(line[2]),int(line[3])))

pos_c = int(int(line[1])/int(line[2])) 
pos_d = int(int(line[1])/int(line[3])) 
pos_lcm = int(int(line[1])/lcm)

pos_c1 = int((int(line[0])-1)/int(line[2])) 
pos_d1 = int((int(line[0])-1)/int(line[3])) 
pos_lcm1 = int((int(line[0])-1)/lcm)

b = int(line[1]) - pos_c - pos_d + pos_lcm
a = int(line[0]) - 1 - pos_c1 - pos_d1 + pos_lcm1

print(b-a)

Submission status: Wrong Answer

Solution code:
line = input().split()
import fractions
cd = int(int(line[2])*int(line[3]) / fractions.gcd(int(line[2]),int(line[3])))

total = int(line[1]) - int(line[0]) + 1

pos_c = int(int(line[1])/int(line[2])) - int((int(line[0])-1)/int(line[2]))
pos_d = int(int(line[1])/int(line[3])) - int((int(line[0])-1)/int(line[3]))
pos_cd = int(int(line[1])/cd) - int((int(line[0])-1)/cd)

answer = total - pos_c - pos_d + pos_cd

print(int(answer))

Submission status: Wrong Answer

Solution code:
line = input().split()
import fractions
cd = int(int(line[2])*int(line[3]) / fractions.gcd(int(line[2]),int(line[3])))

total = int(line[1]) - int(line[0]) + 1

pos_c = int(int(line[1])/int(line[2])) - int((int(line[0])-1)/int(line[2]))
pos_d = int(int(line[1])/int(line[3])) - int((int(line[0])-1)/int(line[3]))
pos_cd = int(int(line[1])/cd) - int((int(line[0])-1)/cd)

answer = total - pos_c - pos_d + pos_cd

print(answer)

Submission status: Wrong Answer

Solution code:
# input
left, right, fizz, buzz = map(int, input().split())

# define
nums = right - left + 1
fizzbuzz = fizz * buzz

# main
if left % fizz == 0:
  fizz_nums = right // fizz - left // fizz + 1
else:
  fizz_nums = right // fizz - (left // fizz + 1) + 1

if left % buzz == 0:
  buzz_nums = right // buzz - left // buzz + 1
else:
  buzz_nums = right // buzz - (left // buzz + 1) + 1
  
if left % fizzbuzz == 0:
  fizzbuzz_nums = right // fizzbuzz - left // fizzbuzz + 1
else:
  fizzbuzz_nums = right // fizzbuzz - (left // fizzbuzz + 1) + 1
  
# output 
print(nums - (fizz_nums + buzz_nums - fizzbuzz_nums))
  
# debug
"""
debug = int(input())
if debug == (nums - (fizz_nums + buzz_nums - fizzbuzz_nums)):
  print("AC")
else:
  print("WA")
"""

Submission status: Wrong Answer

Solution code:
def ans(A, B, X):
  a = A - A % X + X
  if a > B:
    if A % X == 0:
      return 1
    else:
      return 0
  else:
    return (B - a)//X + 1
A, B, C, D = map(int, input().split())
print(B - A + 1 - ans(A, B, C) - ans(A, B, D) + ans(A, B, C * D))

Submission status: Wrong Answer

Solution code:
def ans(A, B, X):
  A = A - A % X + X
  if A > B:
    return 0
  else:
    return (B - A)//X + 1
A, B, C, D = map(int, input().split())
print(B - A + 1 - ans(A, B, C) - ans(A, B, D) + ans(A, B, C * D))

Submission status: Wrong Answer

Solution code:
def ans(A, B, X):
  A = A - A % X + X
  if A > B:
    return 0
  else:
    return (B - A + 1)//X
A, B, C, D = map(int, input().split())
print(B - A - ans(A, B, C) - ans(A, B, D) + ans(A, B, C * D))

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

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

tmp = 0
tmp = ((B//lcm(C,D)) - (A//lcm(C,D)))

print(B-A+1-cnt+tmp)

Submission status: Wrong Answer

Solution code:
import math
import fractions
A,B,C,D= map(int,input().split())
c = math.floor(B/C)-math.ceil(A/C) + 1
d = math.floor(B/D)-math.ceil(A/D) + 1
s = C*D//fractions.gcd(C,D)
e = math.floor(B/s)-math.ceil(A/s) + 1
print(B-A+1-c-d+e)

Submission status: Wrong Answer

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

if A%C!=0 and A%D!=0:
    print((B-A+1)-((B-(A//C+1)*C)//C+1+(B-(A//D+1)*D)//D+1-(((B-(A//L+1)*L)//L)+1)))
elif A%C==0 and A%D!=0:
    print((B-A+1)-(((B-(A//C)*C)//C+1)+((B-(A//D+1)*D)//D+1)-((B-(A//L+1)*L)//L+1)))
elif A%C!=0 and A%D==0:
    print((B-A+1)-((B-(A//C+1)*C)//C+1+(B-(A//D)*D)//D+1-(B-(A//L+1)*L)//L-1))
elif A%C==0 and A%D==0 and A%L==0:
    print((B-A+1)-((B-(A//C)*C)//C+1+(B-(A//D)*D)//D+1+(B-(A//L)*L)//L-1))
elif A%C==0 and A%D==0 and A%L!=0:
    print((B-A+1)-((B-(A//C)*C)//C+1+(B-(A//D)*D)//D+1+(B-(A//L+1)*L)//L-1))

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
ac=a/c
acc=a//c
bc=b/c
bcc=b//c
ad=a/d
add=a//d
bd=b/d
bdd=b//d
al=a/l
al1=a//l
bl=b/l
bl1=b//l
if ac==int(ac) or bc==int(bc):
    cans=bcc-acc+1
else:
    cans=bcc-acc
if ad==int(ad) or  bd==int(bd):
    dans=bdd-add+1
else:
    dans=bdd-add
if al==int(al) or  bl==int(bl):
    lans=bl1-al1+1
else:
    lans=bl1-al1   

re=int(x+1-(cans+dans-lans))
print(re)

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
ac=a/c
bc=b/c
ad=a/d
bd=b/d
al=a/l
bl=b/l
if ac==int(ac) or bc==int(bc):
    cans=x//c+1
else:
    cans=x//c
if ad==int(ad) or  bd==int(bd):
    dans=x//d+1
else:
    dans=x//d
if al==int(al) or  bl==int(bl):
    lans=x//l+1
else:
    lans=x//l
        
re=int(x+1-(cans+dans-lans))
print(re)

Submission status: Wrong Answer

Solution code:

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

def gcd(c, d):
    if c < d:
        return gcd(d, c)
    
    while d != 0:
        s = c % d
        c = d
        d = s
        
    return c
    
def lcm(c, d):
    return c * d // gcd(c, d)
    
#print(gcd(C, D))
#print(lcm(C, D))

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

LCM = lcm(C, D)

LCM = B // LCM - A // LCM if A % LCM == 0 else B // LCM - (A // LCM + 1)

c += 1
d += 1
LCM += 1

#print(c, d, LCM)

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

Submission status: Wrong Answer

Solution code:

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

def gcd(c, d):
    if c < d:
        return gcd(d, c)
    
    while d != 0:
        s = c % d
        c = d
        d = s
        
    return c
    
def lcm(c, d):
    return c * d // gcd(c, d)
    
print(gcd(C, D))
print(lcm(C, D))

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

LCM = lcm(C, D)

LCM = B // LCM - A // LCM if A % LCM == 0 else B // LCM - (A // LCM + 1)

c += 1
d += 1
LCM += 1

#print(c, d, LCM)

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

Submission status: Wrong Answer

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

c_fi = c*math.ceil(a/c)
c_last = c*math.floor(b/c)
c_fi_ = math.ceil(a/c)
c_last_ = math.floor(b/c)
c_k = c_last_ - c_fi_ + 1

d_fi = d*math.ceil(a/d)
d_last = d*math.floor(b/d)
d_fi_ = math.ceil(a/d)
d_last_ = math.floor(b/d)
d_k = d_last_ - d_fi_ + 1

cd_fi = (c*d)*math.ceil(a/(c*d))
cd_last = (c*d)*math.floor(b/(c*d))
cd_fi_ = math.ceil(a/(c*d))
cd_last_ = math.floor(b/(c*d))
cd_k = cd_last_ - cd_fi_ + 1

s_c = (c_k*(c_last + c_fi))/2
s_d = int(d_k*(d_last + d_fi)/2)
s_cd = int(cd_k*(cd_last + cd_fi)/2)

print((b-a+1)-(c_k+d_k-cd_k))

Submission status: Wrong Answer

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

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

i_max=b//c
j_max=b//d
k_max=b//lcm(c,d)

i_min=a//c
j_min=a//d
k_min=a//lcm(c,d)

i=i_max-i_min
j=j_max-j_min
k=k_max-k_min

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

Submission status: Wrong Answer

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

if (B-(A+C-A%C))<0:
    cs=0
else:
    cs=(B-(A+C-A%C))//C+1
if (B-(A+D-A%D))<0:
    ds=0
else:
    ds=(B-(A+D-A%D))//D+1
if (B-(A+(C+D)-A%(C+D)))<0:
    cds=0
else:
    cds=(B-(A+C+D-A%(C+D)))//(C+D)+1


print(B-A-(cs+ds-cds))

Submission status: Wrong Answer

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