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
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def diff(i, j, k):
	return (j // k) - ( i // k)

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

zedd = diff(a, b+1, c) + diff(a, b+1, d) - diff(a, b+1, lcm(c,d))
ans = (b-a+1) -zedd

print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
m_c=(b-a+1)//c
m_d=(b-a+1)//d
m_cd=(b-a+1)//(c*d)
print( (b-a+1)-m_c-m_d+m_cd )

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)

m=lcm(c, d)
n=m-(m/c+m/d-1)
count=n*((b-a)//m)

for i in range(a+((b-a)//m)*m,b+1):
    if i%c!=0 and i%d!=0:
        count+=1
print(int(count))

Submission status: Wrong Answer

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

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

def anti_division(a,b,c,d):
    ans = 0
#    import pdb;pdb.set_trace()
    g = gcd(c,d)
    l = c*d//g
    ua = a - 1

    dupb = b//l
    numbc  = b//c
    numbd  = b//d

    dupa = ua//l
    numac  = ua//c
    numad  = ua//d


    ans = b - ua - (numbc - numac) - (numbd - numad) + dupb + dupa


    return ans
if __name__ == '__main__':
    a,b,c,d = map(int,raw_input().split())
    print anti_division(a,b,c,d)

Submission status: Wrong Answer

Solution code:
import fractions

n=[int(x) for x in input().split()]

a=(n[0]-1)//n[2]
b=(n[0]-1)//n[3]
c=(n[0]-1)//(n[2]*n[3]/fractions.gcd(n[2],n[3]))

d=n[1]//n[2]
e=n[1]//n[3]
f=n[1]//(n[2]*n[3]/fractions.gcd(n[2],n[3]))

print((n[1]-d-e+f)-((n[0]-1)-a-b+c))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
def saidai(x,y):
    tmp = y
    cnt = 0
    while x>y:
        y +=tmp
        cnt +=1
    return(cnt)

sc = saidai(a,c)
lc = saidai(b,c)
sd = saidai(a,c)
ld = saidai(b,d)
scd = saidai(a,c*d)
lcd = saidai(b,c*d)
num_c = lc - sc + 2
num_d = ld - lc + 2
num_cd = lcd -scd +2
print(num_c + num_d - num_cd)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=[int(x) for x in input().split()]

cnt=0

for i in range(n[0],n[1]+1):
    print(i)
    if i%n[2]!=0 and i%n[3]!=0:
        cnt+=1

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cc=c
dd=d
susplus = 1
while susplus != 0:
    susplus = dd % cc
    dd = cc
    cc = susplus
gcd = dd
lcm = (c*d)/gcd

sum = b-a+1
x = (b//c) - ((a-1)//c)
y = (b//d) - ((a-1)//d)
z = (b//(lcm)) - ((a-1)//(lcm))
n_i = x+y-z
print(int(sum-n_i))

Submission status: Wrong Answer

Solution code:
import sys,fractions,math
A,B,C,D = map(int,input().split())
lcm = C * D // fractions.gcd(C,D)
def d_num(x):
    a = A/x
    b = B/x
    if a.is_integer() and b.is_integer():
        return int(b-a+1)
    elif a.is_integer():
        return math.ceil(b) - int(a)
    else :
        return int(b) - int(a)
print(B - A + 1 - (d_num(C)+d_num(D)-d_num(lcm)))

Submission status: Wrong Answer

Solution code:
import sys,fractions,math
A,B,C,D = map(int,input().split())
lcm = C * D // fractions.gcd(C,D)
def d_num(x):
    a = A/x
    b = B/x
    if a.is_integer() and b.is_integer():
        return int(b-a+1)
    elif a.is_integer():
        return int(math.ceil(b) - int(a))
    else :
        return (int(b) - int(a))
print(int(B - A + 1 - (d_num(C)+d_num(D)-d_num(lcm))))

Submission status: Wrong Answer

Solution code:
import sys,fractions,math
A,B,C,D = map(int,input().split())
lcm = C * D // fractions.gcd(C,D)
def d_num(x):
    a = A/x
    b = B/x
    if a.is_integer() and b.is_integer():
        return b-a+1
    elif a.is_integer():
        return math.ceil(b) - int(a)
    else :
        return int(b) - int(a)
print(int(B - A + 1 - (d_num(C)+d_num(D)-d_num(lcm))))

Submission status: Wrong Answer

Solution code:
import sys,fractions,math
A,B,C,D = map(int,input().split())
lcm = C * D // fractions.gcd(C,D)
def d_num(x):
    a = A/x
    b = B/x
    if a.is_integer() and b.is_integer():
        return b-a+1
    elif a.is_integer():
        return math.ceil(b) - int(a)
    else :
        return int(b) - int(a)
print(B - A + 1 - (d_num(C)+d_num(D)-d_num(lcm)))

Submission status: Wrong Answer

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

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

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

ctr = 0

tmp1 = B // int(lcm(C,D))
tmp4 = B // C
tmp5 = B // D
 
print(int(B - tmp4 - tmp5 + tmp1))

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
 
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
 
ctr = 0
 
tmp1 = A // C # 1
tmp2 = A // D # 1
#tmp3 = B // int((C * D / gcd(C,D))) # 24
tmp4 = B // C
tmp5 = B // D
 
print(int(tmp4 + tmp5 - tmp2 - tmp1))

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
 
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
 
ctr = 0
 
tmp1 = A // C
tmp2 = A // D
tmp3 = B // (C * D / gcd(C,D))
tmp4 = B // C
tmp5 = B // D
 
print(int(tmp4 + tmp5 - tmp3 - tmp1 -tmp2))

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
 
ctr = 0
 
for i in range(A,B):
  if (i % C) != 0 and (i % D) != 0:
    ctr += 1
 
print(ctr)

Submission status: Wrong Answer

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

ctr = 0

for i in range(A,B):
  if (i % C) != 0 and (i % D) != 0:
    ctr += 1

print(ctr)

Submission status: Wrong Answer

Solution code:
import math

a,b,c,d=map(int,input().split())
cnt=0
for i in range(a,b):
    #print(i,math.ceil(i % c),math.ceil(i % d))
    if math.ceil(i % c) and math.ceil(i % d):
        cnt+=1
print(cnt)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions as f
a, b, c, d = map(int, input().split())
l = b - a
cd = (c * d // f.gcd(c, d))
print(l - (l // c) - (l // d) + (l // cd))

Submission status: Wrong Answer

Solution code:
import math
import fractions
l, r, p1, p2 = list(map(int, input().split()))
lcm = int(p1*p2 / fractions.gcd(p1, p2))
ans = (r-l+1) - (math.floor(r/p1)-math.ceil(l/p1)+1) - (math.floor(r/p2)-math.ceil(l/p2)+1) + math.floor(r/lcm)-math.ceil(l/lcm)+1
print(ans)

Submission status: Wrong Answer

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

ans = 0
ba = b - a
for i in range(a,b):
  if i % c == 0 or i % d == 0:
    ans += 1
    
print(int(ba - ans))

Submission status: Wrong Answer

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

ans = 0

for i in range(a,b):
  if i % c != 0 and i % d != 0:
    ans += 1
    
print(int(ans))

Submission status: Wrong Answer

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

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

E = C * D // gcd(C, D)
ac = (A-1) // C
ad = (A-1) // D
acd = (A-1) // E
bc = B // C
bd = B // D
bcd = B // E

print(B-A+1-(bc-ac)-(bd-ac)+(bcd-acd))

Submission status: Wrong Answer

Solution code:
import math
l, r, p1, p2 = list(map(int, input().split()))
ans = (r-l+1) - (math.floor(r/p1)-math.ceil(l/p1)+1) - (math.floor(r/p2)-math.ceil(l/p2)+1)
if p1*p2 <= r:
    ans += math.floor(r/(p1*p2))-math.ceil(l/(p1*p2))+1
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

a,b,c,d = [int(i) for i in input().split()]

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

numb = b - (b//c) - (b//d) + (b//lcmcd)
numa = a-1 - ((a-1)//c) - ((a-1)//d) + ((a-1)//lcmcd)

print(int(numb-numa))

Submission status: Wrong Answer

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

for i in range(A,B):
    if i%C != 0 and i%D != 0:
        count += 1

print(count)

Submission status: Wrong Answer

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

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

def nr_divide(a: int, b: int, x: int):
    return b//x - int(math.ceil(a/x)) + 1

def solve(A: int, B: int, C: int, D: int):
    E = my_lcm(C, D)
    N = B - A + 1
    nrC = nr_divide(A, B, C)
    nrD = nr_divide(A, B, D)
    nrE = nr_divide(A, B, E)
    count = N - nrC - nrD + nrE
    print(count)
    return

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

def nr_divide(a: int, b: int, x: int):
    return int(math.floor(b/x)) - int(math.ceil(a/x)) + 1

def solve(A: int, B: int, C: int, D: int):
    E = my_lcm(C, D)
    N = B - A + 1
    nrC = nr_divide(A, B, C)
    nrD = nr_divide(A, B, D)
    nrE = nr_divide(A, B, E)
    count = N - nrC - nrD + nrE
    print(count)
    return

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

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()[:4])

total=B-A+1

C_div=B//C-int(math.ceil(A/C))+1
D_div=B//D-int(math.ceil(A/D))+1

CD=lcm(C,D)

CD_div=B//CD-int(math.ceil(A/CD))+1

print(total-C_div-D_div+CD_div)

Submission status: Wrong Answer

Solution code:
import math

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()[:4])

total=B-A+1

C_div=B//C-math.ceil(A/C)+1
D_div=B//D-math.ceil(A/D)+1

CD=lcm(C,D)

CD_div=B//CD-math.ceil(A/CD)+1

print(total-C_div-D_div+CD_div)

Submission status: Wrong Answer

Solution code:
import math

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()[:4])

total=B-A+1

C_div=int(math.floor(B/C)-math.ceil(A/C)+1)
D_div=int(math.floor(B/D)-math.ceil(A/D)+1)

CD=lcm(C,D)

CD_div=int(math.floor(B/CD)-math.ceil(A/CD)+1)

print(total-C_div-D_div+CD_div)

Submission status: Wrong Answer

Solution code:
import math

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()[:4])

total=B-A+1

C_div=math.floor(B/C)-math.ceil(A/C)+1
D_div=math.floor(B/D)-math.ceil(A/D)+1

CD=lcm(C,D)

CD_div=math.floor(B/CD)-math.ceil(A/CD)+1

print(total-C_div-D_div+CD_div)

Submission status: Wrong Answer

Solution code:
import math

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()[:4])

total=B-A+1

C_div=math.floor(B/C)-math.ceil(A/C)+1
D_div=math.floor(B/D)-math.ceil(A/D)+1

CD=0

if C>=D:
    CD=lcm(C,D)
else:
    CD=lcm(D,C)

CD_div=math.floor(B/CD)-math.ceil(A/CD)+1

#print(total,C_div,D_div,CD_div)
print(total-C_div-D_div+CD_div)

Submission status: Wrong Answer

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

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

temp=input().split()
A=int(temp[0])
B=int(temp[1])
C=int(temp[2])
D=int(temp[3])

x=int(B/C)-int((A-1)/C)
y=int(B/D)-int((A-1)/D)
s=lcm(C, D)
z=int(B/s)-int((A-1)/s)

print(int(B-A+1-x-y+z))

Submission status: Wrong Answer

Solution code:
temp=input().split()
A=int(temp[0])
B=int(temp[1])
C=int(temp[2])
D=int(temp[3])

x=int(B/C)-int((A-1)/C)
y=int(B/D)-int((A-1)/D)
z=int(B/(C*D))-int((A-1)/(C*D))

print(int(B-A+1-x-y+z))

Submission status: Wrong Answer

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

nc = int(b/c) - int((a-1)/c)
# print(nc)

nd = int(b/d) - int((a-1)/d)
# print(nd)

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

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

ncd = int(b/lcm(c,d)) - int((a-1)/lcm(c,d))
# print(ncd)

u = b - a + 1
# print(u)

ans = u - nc - nd + ncd

print(ans)

Submission status: Wrong Answer

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

nc = int(b/c) - int((a-1)/c)
# print(nc)

nd = int(b/d) - int((a-1)/d)
# print(nd)

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

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

ncd = int(b/lcm(c,d)) - int((a-1)/lcm(c,d))
# print(ncd)

u = b - a + 1
# print(u)

ans = u - nc - nd + ncd

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

A, B, C, D = map(int, input().split())
k = B - A + 1
A -= 1
count = int((B//C + B//D - B//((C*D)/fractions.gcd(C, D)))-(A//C + A//D - A//((C*D)/fractions.gcd(C, D))))
print(k-count)

Submission status: Wrong Answer

Solution code:
import fractions

A, B, C, D = map(int, input().split())
k = B - A + 1
A -= 1
count = round((B//C + B//D - B//((C*D)/fractions.gcd(C, D)))-(A//C + A//D - A//((C*D)/fractions.gcd(C, D))))
print(k-count)

Submission status: Wrong Answer

Solution code:
a, b, c, d = [int(e) for e in input().split()]

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

def f(a, b, n):
  return b // n - a // n

acc = 0
acc += f(a, b, c)
acc += f(a, b, d)
acc -= f(a, b, c * d // gcd(c, d))
print(b - a + 1 - acc)

Submission status: Wrong Answer

Solution code:
a, b, c, d = [int(e) for e in input().split()]

def f(a, b, n):
  if b < n:
    return 0
  return (b - a + (n - a % n)) // n 

acc = 0
acc += f(a, b, c)
acc += f(a, b, d)
acc -= f(a, b, c * d)
print(b - a + 1 - acc)

Submission status: Wrong Answer

Solution code:
a, b, c, d = [int(e) for e in input().split()]

def f(a, b, n):
  if b > n:
    return 0
  return (b - a + (n - a % n)) // n 

acc = 0
acc += f(a, b, c)
acc += f(a, b, d)
acc -= f(a, b, c * d)
print(b - a + 1 - acc)

Submission status: Wrong Answer

Solution code:
a, b, c, d = [int(e) for e in input().split()]

def f(a, b, n):
  return (b - a + (n - a % n)) // n 

acc = 0
acc += f(a, b, c)
acc += f(a, b, d)
acc -= f(a, b, c * d)
print(b - a + 1 - acc)

Submission status: Wrong Answer

Solution code:
#ABC131 C
import fractions

A, B, C, D = map(int, input().split())
def ad(X):
    XmodC = X // C
    XmodD = X // D
    CD_lcm = C * D / fractions.gcd(C, D)
    XmodCD = X // CD_lcm
    return int(X - (XmodC + XmodD - XmodCD))
ans = int(ad(B) - ad(A - 1))
print(ans)

Submission status: Wrong Answer

Solution code:
#ABC131 C
import fractions

A, B, C, D = map(int, input().split())
def ad(X):
    XmodC = X // C
    XmodD = X // D
    CD_lcm = C * D / fractions.gcd(C, D)
    XmodCD = X // CD_lcm
    return X - (XmodC + XmodD - XmodCD)
ans = int(ad(B) - ad(A-1))
print(ans)

Submission status: Wrong Answer

Solution code:
#ABC131 C
import fractions

A, B, C, D = map(int, input().split())
def ad(X):
    XmodC = X // C
    XmodD = X // D
    CD_lcm = C * D / fractions.gcd(C, D)
    XmodCD = X // CD_lcm
    return X - int(XmodC + XmodD - XmodCD)
ans = int(ad(B) - ad(A - 1))
print(ans)

Submission status: Wrong Answer

Solution code:

def gcd(m, n):
    if(n == 0):
        return m
    return gcd(n, m % n)


(a, b, c, d) = [int(i) for i in input().split()]
c_d_lcm = (c * d) // gcd(c, d)
able_c_div = (b - a) // c
able_d_div = (b - a) // d
able_c_d_div = (b - a) // c_d_lcm
diff = b - a
print(diff - (able_c_div + able_d_div - able_c_d_div))

Submission status: Wrong Answer

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


def l_c_m(x, y):
    return x * y // g_c_d(x, y)


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

Submission status: Wrong Answer

Solution code:
# -*- coding: UTF-8 -*-
# ABC131_C

import math


def Gcd(x, y):
    while(y):
        x, y = y, x % y
    return x


def Lcm(x, y):
    lcm = (x * y) // Gcd(x, y)
    return lcm


A, B, C, D = map(int, input().split())
CDlcm = Lcm(C, D)
m = A / C
n = B / C
q = A / D
r = B / D
s = A / CDlcm
t = B / CDlcm

setC = math.floor(n) - math.ceil(m) + 1
setD = math.floor(r) - math.ceil(q) + 1
setCD = math.floor(t) - math.ceil(s) + 1
Ans = (B - A + 1) - (setC + setD - setCD)

print(Ans)

Submission status: Wrong Answer

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

ans = int(0)
for x in range(a,b):
  if x%c!=0 and x%d!=0:
    ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a, b, c, d = map(int, input().split())
def calc(x):
    u = x // c
    v = x // d
    w = x // (c * d / gcd(c, d))
    return x - u - v + w
print(int(calc(b) - calc(a - 1)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a, b, c, d = map(int, input().split())
def calc(x):
    u = x // c
    v = x // d
    w = x // (c * d / gcd(c, d))
    return x - u - v + w
print(calc(b) - calc(a - 1))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions


def main():
    A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()]

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

    z = B//C_D - A//C_D

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

    y = B//D - A//D

    print((B-A+1)-(x+y-z))

    print(A, B, C, D)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math


def main():
    A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()]

    # C_D = (C * D) // math.gcd(C, D)

    # z = B//C_D - A//C_D

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

    # y = B//D - A//D

    # print((B-A+1)-(x+y-z))

    print(A, B, C, D)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

import math
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def lcm(a, b):
    return a * b / gcd(a, b)

def dvi_num(b, c):
    return math.floor(b / c)


def dvi_num2(b, c, d):
    return b - dvi_num(b,c) - dvi_num(b,d) + dvi_num(b, lcm(c, d))

ans = 0
if (A != B):
    ans = dvi_num2(B, C, D) - dvi_num2(A - 1, C, D)

print(ans)

Submission status: Wrong Answer

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

import math
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def lcm(a, b):
    return a * b / gcd(a, b)

def dvi_num(b, c):
    return math.floor(b / c)


def dvi_num2(b, c, d):
    return b - dvi_num(b,c) - dvi_num(b,d) + dvi_num(b, lcm(c, d))

ans = dvi_num2(B, C, D) - dvi_num2(A - 1, C, D)

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)

x=b//c-(a-0.1)//c
y=b//d-(a-0.1)//d
z=b//lcm(c,d)-(a-0.1)//lcm(c,d)

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

Submission status: Wrong Answer

Solution code:
import fractions

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

mc = b // c
md = b // d
mcd = b // ((c * d) / (fractions.gcd(c, d)))

mb = b - mc - md + mcd

amc = (a - 1) // c
amd = (a - 1) // d
amcd = (a - 1) // ((c * d) / fractions.gcd(c, d))

ma = (a - 1) - amc - amd + amcd

print(int(mb - ma))

Submission status: Wrong Answer

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

C_mod0 = B//C - (A-1)//C
D_mod0 = B//D - (A-1)//D
CD_mod0 = B//(C*D) -(A-1)//(C*D)
Total = B - A + 1
ans = Total - C_mod0 - D_mod0 + CD_mod0
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
u = b - a + 1
import math
div_c = set()
div_d = set()
for i in range(1,math.floor(math.sqrt(c))+2):
    if c % i == 0:
        div_c.add(i)
for i in range(1,math.floor(math.sqrt(d))+2):
    if d % i == 0:
        div_d.add(i)
gcd = max(list(div_c & div_d))
cd = c*d//gcd
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = b//cd - (a-1)//cd
print(u - n_c - n_d + n_cd)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
u = b - a + 1
import math
div_c = set()
div_d = set()
for i in range(1,math.floor(math.sqrt(c))+1):
    if c % i == 0:
        div_c.add(i)
for i in range(1,math.floor(math.sqrt(d))+1):
    if d % i == 0:
        div_d.add(i)
gcd = max(list(div_c & div_d))
cd = int(c*d/gcd)
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = b//cd - (a-1)//cd
print(u - n_c - n_d + n_cd)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
u = b - a + 1
import math
div_c = set()
div_d = set()
for i in range(1,math.floor(math.sqrt(c))+1):
    if c % i == 0:
        div_c.add(i)
for i in range(1,math.floor(math.sqrt(d))+1):
    if d % i == 0:
        div_d.add(i)
gcd = max(list(div_c & div_d))
cd = (c*d/gcd)
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = b//cd - (a-1)//cd
print(u - n_c - n_d + n_cd)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
u = b - a + 1
import math
div_c = set()
div_d = set()
for i in range(1,int(math.sqrt(c))+1):
    if c % i == 0:
        div_c.add(i)
for i in range(1,int(math.sqrt(d))+1):
    if d % i == 0:
        div_d.add(i)
gcd = max(list(div_c & div_d))
cd = int(c*d/gcd)
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = b//cd - (a-1)//cd
print(u - n_c - n_d + n_cd)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
u = b - a + 1
import math
div_c = set()
div_d = set()
for i in range(1,int(math.sqrt(c))+1):
    if c % i == 0:
        div_c.add(i)
for i in range(1,int(math.sqrt(d))+1):
    if d % i == 0:
        div_d.add(i)
gcd = max(list(div_c & div_d))
cd = c*d/gcd    
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = int(b//cd - (a-1)//cd)
print(u - n_c - n_d + n_cd)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
u = b - a + 1
import math
div_c = set()
div_d = set()
for i in range(1,int(math.sqrt(c))+1):
    if c % i == 0:
        div_c.add(i)
print(div_c)
for i in range(1,int(math.sqrt(d))+1):
    if d % i == 0:
        div_d.add(i)
print(div_d)
gcd = max(list(div_c & div_d))
cd = c*d/gcd    
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = int(b//cd - (a-1)//cd)
print(u - n_c - n_d + n_cd)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
u = b - a + 1
import math
div_c = set()
div_d = set()
for i in range(1,int(math.sqrt(c))+1):
    if c % i == 0:
        div_c.add(i)
for i in range(1,int(math.sqrt(d))+1):
    if d % i == 0:
        div_d.add(i)
gcd = max(list(div_c & div_d))
cd = c*d/gcd    
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = b//(cd) - (a-1)//(cd)
print(int(u - n_c - n_d + n_cd))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
u = b - a + 1
import math
div_c = set()
div_d = set()
for i in range(1,c+1):
    if c % i == 0:
        div_c.add(i)
for i in range(1,d+1):
    if d % i == 0:
        div_d.add(i)
gcd = max(list(div_c & div_d))
cd = c*d/gcd    
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = b//(cd) - (a-1)//(cd)
print(int(u - n_c - n_d + n_cd))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
Lis = list(map(int,input().split()))
if Lis[0] == Lis[1]:
  if Lis[0] == Lis[2] or Lis[0] == Lis[3]:
    print(0)
  else:
    print(1)
elif Lis[2] == Lis[3]:
  print(Lis[1]//Lis[2] - (Lis[0]-1)//Lis[2])
else:
  print(Lis[1]-Lis[1]//Lis[2]-Lis[1]//Lis[3]+Lis[1]//(Lis[2]+Lis[3]) - (Lis[0]- 1) + (Lis[0]-1)//Lis[2] + (Lis[0]-1)//Lis[3] - (Lis[0]-1)//(Lis[2]+Lis[3]))

Submission status: Wrong Answer

Solution code:
Lis = list(map(int,input().split()))
if Lis[0] == Lis[1]:
  if Lis[0] == Lis[2] or Lis[0] == Lis[3]:
    print(0)
  else:
    print(1)
elif Lis[2] == Lis[3]:
  print(Lis[1]//Lis[2] - Lis[0]//Lis[2])
else:
  print(Lis[1]-Lis[1]//Lis[2]-Lis[1]//Lis[3]+Lis[1]//(Lis[2]+Lis[3]) - Lis[0] + Lis[0]//Lis[2] + Lis[0]//Lis[3] - Lis[0]//(Lis[2]+Lis[3]))

Submission status: Wrong Answer

Solution code:
Lis = list(map(int,input().split()))
print(Lis[1]-Lis[1]//Lis[2]-Lis[1]//Lis[3]+Lis[1]//(Lis[2]+Lis[3]) - Lis[0] + Lis[0]//Lis[2] + Lis[0]//Lis[3] - Lis[0]//(Lis[2]+Lis[3]))

Submission status: Wrong Answer

Solution code:
a, b, c, d  = map(int,input().split())
import math
def divbyk(k):
    return    b//k-(a-1)//k

def gcd(x,y):
    n = min(x,y)
    m = max(x,y)
    if n == 0:
        return m
    else:
        return gcd(n,m-(m//n)*n)

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

Submission status: Wrong Answer

Solution code:
a, b, c, d  = map(int,input().split())
import math
def divbyk(k):
    return    b//k-(a-1)//k

def gcd(x,y):
    n = min(x,y)
    m = max(x,y)
    if n == 0:
        return m
    else:
        return gcd(n,m-(m//n)*n)

ans = b-a+1-divbyk(c)-divbyk(d)+divbyk(c*d/gcd(c,d))
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d  = map(int,input().split())
import math
def divbyk(k):
    return    math.floor(b/k)-math.floor((a-1)/k)

def gcd(x,y):
    n = min(x,y)
    m = max(x,y)
    if n == 0:
        return m
    else:
        return gcd(n,m-(m//n)*n)

ans = b-a+1-divbyk(c)-divbyk(d)+divbyk(c*d/gcd(c,d))
print(ans)

Submission status: Wrong Answer

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

cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
s=b//(c*d/fractions.gcd(c,d))-(a-1)//(c*d/fractions.gcd(c,d))


print(int((b-(a-1)-(cc+dd-s))))

Submission status: Wrong Answer

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

def gcd(a,b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b
def fine(a,b,c):
    return 
res = 0
e = (c*d)//gcd(c ,d)
res-= a//c - b//c
print(res)
res-= a//d - b//d
print(res)
res+= a//e - b//e
print(b-a-res+1)
print(a,b,res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#gcd関数(最大公約数を求める)
from fractions import gcd
import math
a,b,c,d = map(int,input().split())

#c,dにおける最小公倍数を求める
z = c*d // gcd(c,d)
#aからbまでの全体の個数
i = b - a + 1
#(l,r)の範囲でgの倍数の個数
#k= (r+g)-(l+g-1)/g
#最小公倍数で割れる個数
y = ((b + z) - (a + z - 1)) / z
#四捨五入して切り捨てる
y = math.floor(y)
#cで割り切れる個数
x = ((b + c) - (a + c - 1)) / c
x = math.floor(x)
#dで割り切れる個数
w = ((b + d) - (a + d - 1)) / d
w = math.floor(w)
#全体からcの倍数とdの倍数を引いて、最小公倍数を足す
print(i - x - w + y)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
lcm=1;mx=0;dc1=0;dd1=0;dl1=0;dt=0
mx=max(c,d)
i=mx
while(1):
    if i%c==0and i%d==0:
        lcm=i
        break
    i+=mx
dc1=int(b/c)-int((a-1)/c)
dd1=int(b/d)-int((a-1)/d)
dl1=int(b/lcm)-int((a-1)/lcm)
dt=dc1+dd1-dl1
print(b-a+1-dt)

Submission status: Wrong Answer

Solution code:
from fractions import gcd


def solve(string):
    a, b, c, d = map(int, string.split())
    _gcd = gcd(c, d)
    lcd = (c // _gcd) * (d // _gcd) * _gcd
    return str(b - a + 1 - (b // c - (a - 1) // c + b // d - (a - 1) // d - b // lcd) +
               (a - 1) // lcd)


if __name__ == '__main__':
    print(solve(input()))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A, B, C, D = map(int, input().split())
if(A % C == 0):
    c_div = (B // C) - (A // C) + 1
else:
    c_div = (B // C) - (A // C + 1) + 1
if(A % D == 0):
    d_div = (B // D) - (A // D) + 1
else:
    d_div = (B // D) - (A // D + 1) + 1
cd_lcm = (C * D) // gcd(C, D)
cd_div = (B // cd_lcm) - (A // cd_lcm + 1) + 1
print((B - A) - (c_div + d_div - cd_div) + 1)

Submission status: Wrong Answer

Solution code:
import fractions

def x(k, c, d):
    rl1 = k
    lcm = c*d / fractions.gcd(c,d)
    ccount = rl1 // c
    dcount = rl1 // d
    cdcount = rl1 // lcm
    # if lcm != 0:
    #     cdcount = int(rl1 // lcm)
    # else:
    #     cdcount = 0

    return rl1 - ccount - dcount + cdcount

a, b, C, D = map(int, input().split())
print(x(b, C, D) - x(a-1, C, D))

Submission status: Wrong Answer

Solution code:
import fractions

def x(k, c, d):
    rl1 = k
    lcm = c*d / fractions.gcd(c,d)
    ccount = int(rl1 // c)
    dcount = int(rl1 // d)
    if lcm != 0:
        cdcount = int(rl1 // lcm)
    else:
        cdcount = 0

    return int(rl1 - ccount - dcount + cdcount)

a, b, C, D = map(int, input().split())
print(x(b, C, D) - x(a-1, C, D))

Submission status: Wrong Answer

Solution code:
import io
import sys


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
314159265358979323 846264338327950288 419716939 937510582
'''


def MAIN():
  # T_IN()
  A()


def A():
  a, b, c, d = IN_L_I()

  divc = (b // c) - ((a - 1) // c)
  divd = (b // d) - ((a - 1) // d)
  divcd = (b // (c * d)) - ((a - 1) // (c * d))


  total = (b + 1 - a) - divc - divd + divcd

  print(total)
  return None
 

def B():
  return None


def C():
  return None


MAIN()