TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):

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

def calc_lcd(x, y):
    if x < y:
        temp = x
        x = y
        y = temp
    
    r = x % y
    z = x * y
    while r != 0:
        x = y
        y = r
        r = x % y
    
    return z // y

lcd = calc_lcd(c, d)
a -= 1
print(b // d)

print(b - b // c - b // d + b // lcd - a - a // c - a // d + a // lcd)



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

def calc_lcd(x, y):
    if x < y:
        temp = x
        x = y
        y = temp
    
    r = x % y
    z = x * y
    while r != 0:
        x = y
        y = r
        r = x % y
    
    return z // y

lcd = calc_lcd(c, d)
a -= 1
#print(b // d)

print(b - b // c - b // d + b // lcd - a - a // c - a // d + a // lcd)


from math import gcd

a, b, c, d = map(int, input().split())
a -= 1
lcm = c * d // gcd(c, d)
cnt_b = b - b // c - b // d + b // lcm
cnt_a = a - a // c - a // d + a // lcm
print(cnt_b - cnt_a)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math
A,B,C,D=map(int,input().split())

c=(int((B-B%C)-(A-1+C-(A-1)%C))/C+0.5)+1
d=(int((B-B%D)-(A-1+D-(A-1)%D))/D+0.5)+1
lcm=C*D/math.gcd(C,D)
candd=((B-B%lcm)-(A-1+lcm-(A-1)%lcm))/lcm+1
print(int(B-A+1-c-d+candd))

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

c=((B-B%C)-(A-1+C-(A-1)%C))//C+1
d=((B-B%D)-(A-1+D-(A-1)%D))//D+1
lcm=C*D//math.gcd(C,D)
candd=((B-B%lcm)-(A-1+lcm-(A-1)%lcm))//lcm+1
print(int(B-A+1-c-d+candd))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#
import sys
import math
import numpy as np
import itertools

def gcd(m,n):
    p=max(m,n)
    q=min(m,n)
    if p % q == 0:
        return q
    else:
        return gcd(q,p%q)




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

x = b // c - (a-1) // c
y = b // d - (a-1) // d
e = c * d // lcm(c,d)
z = b // e - (a-1) // e

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



#
import sys
import math
import numpy as np
import itertools

def gcd(m,n):
    p=max(m,n)
    q=min(m,n)
    if p % q == 0:
        return q
    else:
        return gcd(q,p%q)




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

x = b // c - (a-1) // c
y = b // d - (a-1) // d
e = c * d // gcd(c,d)
z = b // e - (a-1) // e

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



Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import math
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)

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

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
ACDcount = (A - 1) // l
Bcount = Decimal(B - (BCcount + BDcount - BCDcount))
Acount = Decimal((A - 1) - (ACcount + ADcount - ACDcount))
print(Decimal(Bcount - Acount))

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
ACDcount = (A - 1) // l
Bcount = Decimal(B - (BCcount + BDcount - BCDcount))
Acount = Decimal((A - 1) - (ACcount + ADcount - ACDcount))
print(Decimal(Bcount - Acount))

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import math
def gcd(a, b):
    if b==0:
        return a
    return gcd(b, a%b)

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

count = 0
lcm = C*D / gcd(C,D)


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


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

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

count = 0
lcm = C*D / gcd(C,D)


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


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

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

count = 0
lcm = C*D // gcd(C,D)


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


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a, b, c, d = map(int, input().split())

c_div_a = a // c
c_div_all = b // c

d_div_a = a // d
d_div_all = b // d

cd_div_a = a // (c*d)
cd_div_all = b // (c*d)

div_a = c_div_a + d_div_a - cd_div_a
div_all = c_div_all + d_div_all - cd_div_all

print( (b - a) - (div_all - div_a) + 1)


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)

c_div_a = (a-1) // c
c_div_all = b // c

d_div_a = (a-1) // d
d_div_all = b // d

cd_div_a = (a-1) // int( lcm(c, d) )
cd_div_all = b // int( lcm(c, d) )

div_a = c_div_a + d_div_a - cd_div_a
div_all = c_div_all + d_div_all - cd_div_all

print( (b - (a-1)) - (div_all - div_a) )


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

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


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

c_div_a = (a-1) // c
c_div_all = b // c

d_div_a = (a-1) // d
d_div_all = b // d


cd_div_a = (a-1) // int( lcm(c, d) )
# print("cd_div_a", cd_div_a)
cd_div_all = b // int( lcm(c, d) )
# print("cd_div_all", cd_div_all)


div_a = c_div_a + d_div_a - cd_div_a
div_all = c_div_all + d_div_all - cd_div_all

print( (b - (a-1)) - (div_all - div_a) )


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a, b, c, d = map(int, input().split())


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

X = b//c - (a-1)//c
Y = b//d - (a-1)//d

CD = c*d / gcd(c, d)
XY = b//CD - (a-1)//CD

print(b-a+1-(X+Y-XY))

A, B, C, D = map(int, input().split())
 
def gcd(a, b):
    while a%b!=0:
        a, b = b, a%b
    return b
 
X = B//C - (A-1)//C
Y = B//D - (A-1)//D
CD = C*D // gcd(C, D)
XY = B//CD - (A-1)//CD
 
print(B-A+1-(X+Y-XY))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a,b,c,d = map(int,input().split())
b_c = b//c
b_d = b//d
a_c = (a-1)//c
a_d = (a-1)//d
b_cd = b//int((c*d)/math.gcd(c, d))
a_cd = (a-1)//int((c*d)/math.gcd(c, d))
print((b-a+1)-(b_c+b_d-b_cd-(a_c+a_d-a_cd)))

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())
b_c = b//c
b_d = b//d
a_c = (a-1)//c
a_d = (a-1)//d
b_cd = b//int((c*d)/gcd(c, d))
a_cd = (a-1)//int((c*d)/gcd(c, d))
print((b-a+1)-(b_c+b_d-b_cd-(a_c+a_d-a_cd)))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
num = input().split(" ")
a = int(num[0])
b = int(num[1])
c = int(num[2])
d = int(num[3])
print(b - b // c - b // d + b // (c * d) -(a - a // c - a // d + a // (a // (c * d)))

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

num = input().split(" ")
a = int(num[0])-1
b = int(num[1])
c = int(num[2])
d = int(num[3])
e = int(c * d / int(gcd(c, d)))
bb = b - (b//c) -(b//d) +(b//e) 
aa = a - (a//c) -(a//d) + (a//e)
print(int(bb-aa))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
a, b, c, d = map(int, input().split())
i, j = c, d
def gcd(i, j):
    return i if j == 0 else GCD(j, i%j)
lcm = int(c//gcd(c, d)*d)

def cont(x):
    cnt1 = x//c 
    cnt2 = x//d
    ans = x - cnt1 - cnt2 + x//lcm
    return int(ans)

print(cont(b) - cont(a-1))

a, b = map(int, input().split())
c, d = map(int, input().split())
lst = []
cnt = 0
for i in range(a, b+1):
    if i%c != 0:
        lst.append(i)
for j in lst:
    if j%d != 0:
        cnt += 1
print(cnt)

a, b, c, d = map(int, input().split())
i, j = c, d
def gcd(i, j):
    return i if j == 0 else gcd(j, i%j)
lcm = int(c//gcd(c, d)*d)

def cont(x):
    cnt1 = x//c 
    cnt2 = x//d
    ans = x - cnt1 - cnt2 + x//lcm
    return int(ans)

print(cont(b) - cont(a-1))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import math

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

s1=b//c - (a-1)//c
s2=b//d - (a-1)//d
s12=b//(c*d/math.gcd(c,d)) - (a-1)//(c*d/math.gcd(c,d))
s12=int(s12)
print(s1,s2,s12)
print(b-a+1-(s1+s2-s12))


import math

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

s1=b//c - a//c
s2=b//d - a//d
s12=int( b//(c*d/math.gcd(c,d)) - a//(c*d/math.gcd(c,d)) )

print(b-a+1-(s1+s2-s12))


import math

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

s1=b//c - math.ceil(a/c) + 1
s2=b//d - math.ceil(a/d) + 1
s12=int( b//(c*d/math.gcd(c,d)) - math.ceil(a/(c*d/math.gcd(c,d))) + 1 )
print(s1,s2,s12)
print(b-a+1-(s1+s2-s12))


import math

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

s1=b//c - (a-1)//c
s2=b//d - (a-1)//d
s12=int( b//(c*d/math.gcd(c,d)) - (a-1)//(c*d/math.gcd(c,d)) )
print(s1,s2,s12)
print(b-a+1-(s1+s2-s12))


import math

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

s1=b//c - a//c
s2=b//d - a//d
s12=int( b//(c*d/math.gcd(c,d)) - a//(c*d/math.gcd(c,d)) )
print(s1,s2,s12)
print(b-a+1-(s1+s2-s12))


import math

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

s1=b//c - (a-1)//c
s2=b//d - (a-1)//d
s12=b//(c*d//math.gcd(c,d)) - (a-1)//(c*d//math.gcd(c,d))
#print(s1,s2,s12)
print(b-a+1-(s1+s2-s12))


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a, b, c, d = [int(v) for v in input().split()]

def gcd(p, q):
    if q > p:
        p, q = q, p
    m = -1
    while m != 0:
        m = p % q
        p, q = q, m
    return p

a = a - 1
lcm = c * d / gcd(d, c)
dc = b//c - a//c
dd = b//d - a//d
dcd = b//lcm - a//lcm
divable = dc + dd - dcd
print(b - a - divable)

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

def gcd(p, q):
    if q > p:
        p, q = q, p
    m = -1
    while m != 0:
        m = p % q
        p, q = q, m
    return p

a = a - 1
lcm = c * d // gcd(d, c)
dc = b//c - a//c
dd = b//d - a//d
dcd = b//lcm - a//lcm
divable = dc + dd - dcd
print(b - a - divable)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math
A, B, C, D = map(int, input().split())
c = B // C - A // C
d = B // D - A // D
E = int((C * D) / math.gcd(C, D))
e = B // E - A // E
print(B - A + 1 - c - d + e)

import math
A, B, C, D = map(int, input().split())
c = B // C - A // C + int(A % C == 0)
d = B // D - A // D + int(A % D == 0)
E = int((C * D) / math.gcd(C, D))
e = B // E - A // E + int(A % E == 0)
print(B - A + 1 - c - d + e)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
e = list(map(int,input().split()))
a = e[0]
b = e[1]
c = e[2]
d = e[3]
cnt = 0
for j in range(a,b+1):
    if j%c != 0 and j%d != 0
        cnt += 1
print(cnt)

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

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

def sums(x):
    S1 = x//c
    S2 = x//d
    S3 = x// (c*d//gcd(c,d))
    return x - S1 - S2 + S3


print(sums(b)-sums(a-1))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import math
a,b,c,d=map(int,input().split())
e=a*b//math.gcd(a,b)
if a%c==0:
  p=b//c-a//c+1
else:
  p=b//c-a//c
if a%d==0:
  q=b//d-a//d+1
else:
  q=b//d-a//d
if a%e==0:
  r=b//e-a//e+1
else:
  r=b//e-a//e
print(b-a+1-(p+q-r))

import math
a,b,c,d=map(int,input().split())
e=c*d//math.gcd(c,d)
if a%c==0:
  p=b//c-a//c+1
else:
  p=b//c-a//c
if a%d==0:
  q=b//d-a//d+1
else:
  q=b//d-a//d
if a%e==0:
  r=b//e-a//e+1
else:
  r=b//e-a//e
print(b-a+1-(p+q-r))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# Euclidean Algorithm
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

# lcm (least common multiple)
def lcm(m, n):
    return m//gcd(m, n)*n

a, b, c, d = map(int, input().split())
ndiv = (b-a+1)//c + (b-a+1)//d - (b-a+1)//lcm(c,d)
print(b - a - ndiv)

# Euclidean Algorithm
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

# lcm (least common multiple)
def lcm(m, n):
    return m//gcd(m, n)*n

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

x = b - a + 1
y = b//c - (a-1)//c 
z = b//d - (a-1)//d
w = b//lcm - (a-1)//lcm

print(x - y - z + w)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def resolve():
    A, B, C, D = map(int, input().split())
    d = D
    c = C
    gcd = 0
    while gcd == 0:
        if d % c == 0:
            gcd = c
            break
        else:
            d = c
            c = d % c
    lcm = C*D//gcd
    A = A-1
    print((B-B//C-B//D+B//lcm)-(A-A//C-A//D+A//lcm))
resolve()

def resolve():
    A, B, C, D = map(int, input().split())
    d = D
    c = C
    gcd = 0
    while gcd == 0:
        if d % c == 0:
            gcd = c
        else:
            e = d%c
            d = c
            c = e
    lcm = C*D//gcd
    A = A-1
    print((B-B//C-B//D+B//lcm)-(A-A//C-A//D+A//lcm))
resolve()

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
#data=list(input().split())
a,b,c,d=map(int,input().split())
def gcd(x , y):
    if y == 0 
        return x 
    else gcd(y, x%y)

def gys(a,b):
    remainder = gcd(a,b)
    return int(a*b/remainder)

lcmm=gys(c,d)
def ans(n,k):
    return int(n/k)
def x(s):
    return ans(s,c)+ans(s,d)-ans(s,lcmm)
#print(x(b),x(a))
if a%c==0 or a%d==0:
    print(b-a-x(b)+x(a))
else:
    print(b-a+1-x(b)+x(a))




#data=list(input().split())
a,b,c,d=map(int,input().split())
def gcd(x , y):
    if y == 0:
        return x 
    else:
        return gcd(y, x%y)

def gys(a,b):
    remainder = gcd(a,b)
    return a*b//remainder

lcmm=gys(c,d)
def ans(n,k):
    return n//k
def x(s):
    return ans(s,c)+ans(s,d)-ans(s,lcmm)
#print(x(b),x(a))

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




Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
S = input().split()

A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

count_U = B - A + 1


#print(count_C)

#print(count_D)

#print(count_CD)

count_C = (B // C) - (A // C)
count_D = (B // D) - (A // D)
CD = lcm(C, D)
count_CD = (B // CD) - (A // CD)

print(count_U - (count_C + count_D - count_CD))

S = input().split()

A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

count_U = B - A + 1


#print(count_C)

#print(count_D)

#print(count_CD)

count_C = math.floor((B // C) - (A // C))
count_D = math.floor((B // D) - (A // D))
CD = lcm(C, D)
count_CD = math.floor((B // CD) - (A // CD))

print(count_U - (count_C + count_D - count_CD))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
    
S = input().split()

A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

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

count_B = B - (B // C) - (B // D) + (B // CD)
count_A = A - 1 - ((A - 1) // C) - ((A - 1) // D) + ((A - 1) // CD)

print(count_B - count_A)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import sys
import math

A,B,C,D = map(int, input().split())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)


maru1 = B // C
maru2 = A // C

maru3 = B // D
maru4 = A // D

maru5 = B // lcm(C,D)
maru6 = A // lcm(C,D)

ans_tmp = ((maru1-maru2)+(maru3-maru4)) - (maru5-maru6)
ans = ((B-A)+1) - ans_tmp

print(ans)

import sys
import math

A,B,C,D = map(int, input().split())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)


maru1 = B // C
maru2 = (A-1) // C

maru3 = B // D
maru4 = (A-1) // D

maru5 = B // lcm(C,D)
maru6 = (A-1) // lcm(C,D)

ans_tmp = ((maru1-maru2)+(maru3-maru4)) - (maru5-maru6)
ans = (B-A+1) - ans_tmp

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math

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

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

g = math.gcd(c, d)
l = lcm(c, d)

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

import math

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

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

g = math.gcd(c, d)
l = lcm(c, d)

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines

def main():

    lines = input()
    a, b, c, d = list(map(int, lines[0].split()))

    def gcd(a, b):

        r = a % b

        if r == 0:
            return int(b)
        
        return gcd(b, r)

    g = gcd(c, d)
    gcm = c * d / g
    print(gcm)


    c_in = int(b // c - (a-1)//c)
    d_in = int(b // d - (a-1)//d)
    cd_in = int(b // gcm - (a-1)//gcm)
    
    ans = int((b-a+1) - (c_in + d_in - cd_in))
    print(ans)

main()


import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines

import math

def main():

    lines = input()
    a, b, c, d = list(map(int, lines[0].split()))

    def gcd(a, b):

        r = a % b

        if r == 0:
            return int(b)
        
        return gcd(b, r)

    g = gcd(c, d)
    gcm = int(c * d / g)

    c_in = int(b // c - (a-1)//c)
    d_in = int(b // d - (a-1)//d)
    cd_in = int(b // gcm - (a-1)//gcm)

    ans = int((b-a+1) - (c_in + d_in - cd_in))
    print(ans)

main()




Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys

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


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


def main():
    input = sys.stdin.readline
    A, B, C, D = map(int, input().split())
    E = lcm(C, D)
    print(E)
    total = B - A + 1
    multi_c = max(0, B // C) - max(0, A // C)
    if A % C == 0:
        multi_c += 1
    multi_d = max(0, B // D) - max(0, A // D)
    if A % D == 0:
        multi_d += 1
    multi_e = max(0, B // E) - max(0, A // E)
    if A % E == 0:
        multi_e += 1
    print(total, multi_c, multi_d, multi_e)
    return total - (multi_c + multi_d - multi_e)


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


import sys

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


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


def main():
    input = sys.stdin.readline
    A, B, C, D = map(int, input().split())
    E = lcm(C, D)

    total = B - (A-1)
    mul_c = B // C - (A-1) // C
    mul_d = B // D - (A-1) // D
    mul_e = B // E - (A-1) // E
    return total - (mul_c + mul_d - mul_e)


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


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math
def gcd(a, b):
  while b:
    a, b = b, a%b
  return a

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

tmp_b= b - math.floor(b/c) - math.floor(b/d)
tmp_b += math.floor(b/(c*d/gcd(c, d)))

tmp_a= a - math.floor(a/c) - math.floor(a/d)
tmp_a += math.floor(a/(c*d/gcd(c, d)))

print(tmp_b-tmp_a+1)


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

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

tmp_b= b - math.floor(b/c) - math.floor(b/d)
tmp_b += math.floor(b/math.floor(c*d/gcd(c, d)))

tmp_a= a - math.floor(a/c) - math.floor(a/d)
tmp_a += math.floor(a/math.floor(c*d/gcd(c, d)))

print(tmp_b-tmp_a+1)

import math
from decimal import Decimal
#from decimal import Decimal
a, b, c, d = map(Decimal, input().split())

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

def count(a, c, d):
    tmp_a= a - math.floor(a/c) - math.floor(a/d)
    tmp_a += math.floor(a/((c*d)/gcd(c, d)))
    return tmp_a

print(int(count(b,c,d))-int(count(a-1, c, d)))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
A,B,C,D = map(int, input().split())

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

lcm=C*D/gcd(C,D)
con1=B//C - (A-1)//C
con2=B//D - (A-1)//D
con3=B//lcm - (A-1)//lcm

print(B-(A-1)-(con1+con2-con3))


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

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

lcm=C*D/gcd(C,D)
con1=B//C - A//C
con2=B//D - A//D
con3=B//lcm - A//lcm

print(B-(A-1)-(con1+con2-con3))

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

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

lcm=C*D//gcd(C,D)
con1=B//C - (A-1)//C
con2=B//D - (A-1)//D
con3=B//lcm - (A-1)//lcm

print(B-(A-1)-(con1+con2-con3))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import fractions
A, B, C, D = map(int, input().split())
Cdiv = B // C - (A - 1) // C
Ddiv = B // D - (A - 1) // D
gcd_CD = C * D / fractions.gcd(C, D)
CDdiv = B // gcd_CD - (A - 1) // gcd_CD
result = int(B - (A - 1) - Cdiv - Ddiv + CDdiv)
print(result)

import fractions
A, B, C, D = map(int, input().split())
Cdiv = B // C - (A - 1) // C
Ddiv = B // D - (A - 1) // D
gcd_CD = C * D / fractions.gcd(C, D)
CDdiv = B // gcd_CD - (A - 1) // gcd_CD
result = int(B - (A - 1) - Cdiv - Ddiv + CDdiv)
print(result)

A, B, C, D = map(int, input().split())
result = 0
size = B - A + 1
for i in range(size):
    if((A + i)%C == 0):
        pass
    elif((A + i)%D ==0):
        pass
    else
        result += 1

print(result)


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

import math
g = math.gcd(c, d)
l = int(c * d / g)

less_b = b - (b // c + b // d - b // l)
less_a = (a-1) - ((a-1)//c + (a-1) // d - (a-1)//l)
print(less_b-less_a)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: 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.

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

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

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

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

A, B, C, D = map(int, input().split())
A -= 1
import math
g = C*D//math.gcd(C, D)
a = A//C + A//D - A//g
b = B//C + B//D - B//g
ans = B - A - b + a
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
A, B, C, D = map(int, input().split())

import math

interval = B-A+1

n1 = math.ceil(A/C)
n2 = math.ceil(A/D)
m1 = math.ceil(B/C)
m2 = math.ceil(B/D)

arr1 = []
arr2 = []

if B%C==0:
    for i in range(n1, m1+1):
        arr1.append(i*C)
else:
    for i in range(n1, m1):
        arr1.append(i*C)
        
if B%D==0:
    for j in range(n2, m2+1):
        arr2.append(j*D)
else:
    for j in range(n2, m2):
        arr2.append(j*D)
    
cnt_c = len(arr1)
cnt_d = len(arr2)
cnt_cd = sum([arr[i]%C==0 for i in range(len(arr))])
cnt = cnt_c+cnt_d-cnt_cd

print(interval-cnt)

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

import math

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

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

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

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import fractions, math
A, B, C, D = map(int, input().split())
U = B - A + 1

MofD = 0
MofCD = 0

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


def sten(st, en, x):
    st = math.ceil(st/x)*x
    en = math.floor(en/x)*x
    if en >= st:
        n = (en - st) // x + 1
    else:
        n = 0
    return n


MofC = sten(A, B, C)
if C != D:
    MofD = sten(A, B, D)
    MofCD = sten(A, B, lcm(C, D))

print(U-MofC-MofD+MofCD)


import math
A, B, C, D = map(int, input().split())
U = B - A + 1


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


def sten(st, en, x):
    st = math.ceil(st/x)*x
    en = math.floor(en/x)*x
    if en >= st:
        n = (en - st) / x + 1
    else:
        n = 0
    return n


MofC = sten(A, B, C)
MofD = sten(A, B, D)
MofCD = sten(A, B, lcm(C, D))

print(U-MofC-MofD+MofCD)

import fractions, math
A, B, C, D = map(int, input().split())
U = B - A + 1


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


def sten(st, en, x):
    st = math.ceil(st/x)*x
    en = math.floor(en/x)*x
    if en >= st:
        n = (en - st) // x + 1
    else:
        n = 0
    return n


MofC = sten(A, B, C)
MofD = sten(A, B, D)
MofCD = sten(A, B, lcm(C, D))

print(U-MofC-MofD+MofCD)



A, B, C, D = map(int, input().split())
U = B - A + 1

MofD = 0
MofCD = 0

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

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


def sten(st, en, x):
    if x == 1:
        return en - st + 1
    st = st // x if st % x == 0 else st // x + 1
    en = en // x
    st *= x
    en *= x
    if en >= st:
        n = (en - st) // x + 1
    else:
        n = 0
    return n


MofC = sten(A, B, C)
if C != D:
    MofD = sten(A, B, D)
    MofCD = sten(A, B, lcm(C, D))

print(U-MofC-MofD+MofCD)


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a,b,c,d = map(int,input().split())
l = [c,d,c*d]
count = 0
for i in range(3):
  if a%l[i] == 0:
    if i < 2:
      count += (1+len(range(a+1,b+1))//l[i])
    else:
      count -= (1+len(range(a+1,b+1))//l[i])
  else:
    if i < 2:
      count += (1+len(range(a+l[i]-a%l[i]+1,b+1))//l[i])
    else:
      count -= (len(range(a+l[i]-a%l[i]+1,b+1))//l[i])
print(len(range(a,b+1))-count)

a,b,c,d = map(int,input().split())
def gcd(x,y):
    while y:
        x, y = y, x%y
    return x
cd = int(c*d/gcd(c,d))
l = [c,d,cd]
count = 0
for i in range(3):
  if a%l[i] == 0:
    if i < 2:
      count += (1+len(range(a+1,b+1))//l[i])
    else:
      count -= (1+len(range(a+1,b+1))//l[i])
  else:
    e = a+l[i]-a%l[i]
    if e <= b:
      if i < 2:
        count += (1+len(range(e+1,b+1))//l[i])
      else:
        count -= (1+len(range(e+1,b+1))//l[i])
    
print(len(range(a,b+1))-count)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
A, B, C D = map(int, input())
ans = 0
for i in range(A, B):
  if i % C == 0 and i % D == 0:
    ans = ans
  else:
    ans = ans + 1
print(ans)

A, B, C D = map(int, input())
ans = 0
for i in range(A, B):
  if i % C == 0 and i % D == 0:
    ans = ans + 1
print(ans)

A, B, C D = map(int, input())
ans = 0
for i in range(A, B):
  if i % C == 0 and i % D == 0:
    ans = ans + 1

def bbb(x, y):
    return (x * y) // aaa(x, y)
 
 
def aaa(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return aaa(y, x % y)
 
 
a, b, c, d = map(int, input().split())
bc = b // c
bd = b // d
ac = (a-1) // c
ad = (a-1) // d
aw = (a-1) // bbb(c, d)
bw = b // bbb(c, d)
print((b - a + 1) - (bc - ac) - (bd - ad) + (bw - aw))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
a,b,c,d = map(int,input().split())
h = a-b + 1
e = c*d
m = h//c + int(a%c==0)
k = h//d + int(a%d==0) 
l = h//e + int(a%e==0)
print(h-(m+k-l))


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


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

import math
a,b,c,d = map(int,input().split())
h = a-b+1
e = c*d//math.gcd(c,d)
print(h-h//c-h//d+h//e)

import math
a,b,c,d = map(int,input().split())
h = a-b
e = c*d//math.gcd(c,d)
print(h-h//c-h//d+h//e)


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

import math
a,b,c,d = map(int,input().split())
a-=1
e = c*d//math.gcd(c,d)
print(b-b//c-b//d+b//e-(a-a//c-a//d+a//e))


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
A, B, C, D = map(int, input().split())

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

g = gcd(C, D) if C < D else gcd(D, C)
ansB = B-B/C-B/D+B/(C*D/g)
ansA = A - 1 - (A-1)/C - (A-1)/D + (A-1)/(C*D/g)
print(ansB-ansA)

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

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

g = gcd(C, D) if C < D else gcd(D, C)
ansB = B-B//C-B//D+B//(C*D//g)
ansA = A - 1 - (A-1)//C - (A-1)//D + (A-1)//(C*D//g)
print(ansB-ansA)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

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

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

E=C*D//gcd(C,D)
total=0
if A%C==0 and A>=C:
    total += B//C-A//C+1
else:
    total += B // C - A // C

if A%D==0 and A>=D:
    total += B//D-A//D+1
else:
    total += B // D - A// D

if A%E==0 and A>=E:
    total = total- B//E-A//E+1
else:
    total = total - B // E - A // E

print(B-A+1-tot

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


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


E = C * D // gcd(C, D)
total = 0

total += B // C - (A-1) // C


total += B // D - (A-1) // D


total = total - B // E + (A-1) // E

print(B - A + 1 - total)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):

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

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

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

s = -1
c = C * (A // C + 1)
if c <= B:
    s += (B - c) // C + 1
        
d = D * (A // D + 1)
if d <= B:
    s += (B - d) // D + 1
    
cd_lcm = lcm(C, D)
cdl = cd_lcm * (A // cd_lcm + 1)
if cdl <= B:
    s -= (B - cdl) // cd_lcm + 1

print(B - A - s)

import math

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

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

s = -1
c = C * (A // C + 1)
if c <= B:
    s += (B - c) // C + 1
        
d = D * (A // D + 1)
if d <= B:
    s += (B - d) // D + 1
    
cd_lcm = lcm(C, D)
cdl = cd_lcm * (A // cd_lcm + 1)
if cdl <= B:
    s -= (B - cdl) // cd_lcm + 1

print(B - A - s)


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

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

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

s = -1
c = C * (A // C + 1)
if c <= B:
    s += (B - c) // C + 1
        
d = D * (A // D + 1)
if d <= B:
    s += (B - d) // D + 1
    
cd_lcm = lcm(C, D)
cdl = cd_lcm * (A // cd_lcm + 1)
if cdl <= B:
    s -= (B - cdl) // cd_lcm + 1

print(B - A - s)


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

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

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

s = -1
c = C * (A // C + 1)
if A % C == 0:
    c = A
if c <= B:
    s += (B - c) // C + 1
        
d = D * (A // D + 1)
if A % D == 0:
    d = A
if d <= B:
    s += (B - d) // D + 1
    
cd_lcm = lcm(C, D)
cdl = cd_lcm * (A // cd_lcm + 1)
if A % cd_lcm == 0:
    cdl = A
if cdl <= B:
    s -= (B - cdl) // cd_lcm + 1

print(B - A - s)

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a,b,c,d = map(int,input().split())

print(int((b-a+1)-(b//c+b//d-a//c-a//d)+(b//(c*d)-a//(c*d))))

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)
cd = lcm(c,d)
print(int((b-a+1)-(b//c+b//d-(a-1)//c-(a-1)//d)+(b//(cd)-(a-1)//(cd))))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def euclid(a, b):
    if a > b:
        large = a
        small = b
    else:
        large = b
        small = a

    while small != 0:
        r = large % small
        large = small
        small = r

    return large


def solve(inputs):
    [A, B, C, D] = string_to_int(inputs[0])
    cd_gcd = euclid(C, D)
    cd_lcm = (C*D) / cd_gcd

    a_c = (A-1) // C
    a_d = (A-1) // D
    a_cd = (A-1) // cd_lcm

    b_c = B // C
    b_d = B // D
    b_cd = B // cd_lcm

    # 4 - (2+1-0) = 1
    under_a = (A-1) - (a_c + a_d - a_cd)
    # 9 - (4 + 3 - 1) = 3
    under_b = B - (b_c + b_d - b_cd)

    return (under_b - under_a)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def euclid(a, b):
    if a > b:
        large = a
        small = b
    else:
        large = b
        small = a

    while small != 0:
        r = large % small
        large = small
        small = r

    return large


def solve(inputs):
    [A, B, C, D] = string_to_int(inputs[0])
    cd_gcd = euclid(C, D)
    cd_lcm = (C*D) // cd_gcd

    a_c = (A-1) // C
    a_d = (A-1) // D
    a_cd = (A-1) // cd_lcm

    b_c = B // C
    b_d = B // D
    b_cd = B // cd_lcm

    under_a = int((A-1) - a_c - a_d + a_cd)
    under_b = int(B - b_c - b_d + b_cd)

    return under_b - under_a


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a,b,c,d = map(int,input().split())
a1 = a//c
a2 = b//c
a3 = a2 - a1 - 1

b1 = a//d
b2 = b//d
b3 = b2 - b1 - 1

width = b - a + 1

print(a3,b3)

print(width - a3 - b3)

a,b,c,d = map(int,input().split())
a1 = a//c
a2 = b//c
a3 = a2 - a1 - 1

b1 = a//d
b2 = b//d
b3 = b2 - b1 - 1

width = b - a + 1

print(width - a3 - b3)

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
a,b,c,d = map(int,input().split())
a1 = a//c
a2 = b//c
a3 = a2 - a1
b1 = a//d
b2 = b//d
b3 = b2 - b1
c3 = (c*d)/gcd(c,d)
width = b - a + 1
print(int(width - a3 - b3 + c3))

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)

a,b,c,d = map(int,input().split())
a3 = b // c - a // c
b3 = b // d - a // d
if c < d:
	c,d = d,c
width = b - a + 1
c3 = b//lcm(c,d) - a//lcm(c,d)
print(int(width - a3 - b3 + c3))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
a,b,c,d = map(int,input().split())
a1 = a//c
a2 = b//c
a3 = a2 - a1
b1 = a//d
b2 = b//d
b3 = b2 - b1
if c < d:
	c,d = d,c
c3 = (c*d)/gcd(c,d)
width = b - a + 1
print(int(width - a3 - b3 + c3))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
a,b,c,d = map(int,input().split())
a1 = a//c
a2 = b//c
a3 = a2 - a1
b1 = a//d
b2 = b//d
b3 = b2 - b1
c3 = (c*d)/gcd(c,d)
width = b - a + 1
print(width - a3 - b3 + c3)

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)

a,b,c,d = map(int,input().split())
a3 = b // c - (a-1) // c
b3 = b // d - (a-1) // d
if c < d:
	c,d = d,c
width = b - a + 1
c3 = b//lcm(c,d) - (a-1)//lcm(c,d)
print(int(width - a3 - b3 + c3))


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a,b,c,d = map(int,input().split())
ans = 0

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

print(ans)

def gcd(x,y):
    if y==0:
        return x
    else:
        return(gcd(y,x%y))
    
a,b,c,d = map(int,input().split())
g = gcd(c,d)
l = c*d//g

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a, b, c, d = map(int, input().split())

first_c = c * a // c + a % c
last_c = c * b // c
first_d = d * a // d + a % d
last_d = d * b // d
cd = c * d
first_cd = cd * a // cd + a % cd
last_cd = cd * b // cd

cnum = (last_c - first_c) // c + 1
dnum = (last_d - first_d) // d + 1
cdnum = (last_cd - first_cd) // cd + 1

print(cnum, dnum, cdnum)
total = cnum + dnum - cdnum
print(b - a + 1 - total)


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

first_c = c * (a // c + 1) - (c - a % c)
last_c = c * b // c
first_d = d * (a // d + 1) + (d - a % d)
last_d = d * b // d
cd = lcm(c, d)
first_cd = cd * (a // cd + 1) + (cd - a % cd)
last_cd = cd * b // cd

cnum = 0
dnum = 0
cdnum = 0

if first_c <= b:
    cnum = (last_c - first_c) // c + 1

if first_d <= b:
    dnum = (last_d - first_d) // d + 1

if first_cd <= b:
    cdnum = (last_cd - first_cd) // cd + 1

total = cnum + dnum - cdnum
print(b - a + 1 - total)


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

first_c = c * (a // c + 1)
if a % c == 0:
    first_c -= c
last_c = c * (b // c)

first_d = d * (a // d + 1)
if a % d == 0:
    first_d -= d
last_d = d * (b // d)

cd = lcm(c, d)
first_cd = cd * (a // cd + 1)
if a % cd == 0:
    first_cd -= cd
last_cd = cd * (b // cd)

cnum = 0
dnum = 0
cdnum = 0

if first_c <= b:
    cnum = (last_c - first_c) // c + 1

if first_d <= b:
    dnum = (last_d - first_d) // d + 1

if first_cd <= b:
    cdnum = (last_cd - first_cd) // cd + 1

total = cnum + dnum - cdnum
print(b - a + 1 - total)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math



#     return n-(math.floor(n / c) +
#               math.floor(n / d) - math.floor(n / (c * d / math.gcd(c, d))))
def calc(n, c, d):
    return n-(n // c +
              n // d - n // (c * d / math.gcd(c, d)))

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

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


if __name__ == "__main__":
    main()


import math



#     return n-(math.floor(n / c) +
#               math.floor(n / d) - math.floor(n / (c * d / math.gcd(c, d))))
def calc(n, c, d):
    return n-(n / c +
              n / d - n / (c * d / gcd(c, d)))


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

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


if __name__ == "__main__":
    main()


import math



#     return n-(math.floor(n / c) +
#               math.floor(n / d) - math.floor(n / (c * d / math.gcd(c, d))))
def calc(n, c, d):
    return n-(n / c +
              n / d - n / (c * d / math.gcd(c, d)))

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

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


if __name__ == "__main__":
    main()


import math



#     return n-(math.floor(n / c) +
#               math.floor(n / d) - math.floor(n / (c * d / math.gcd(c, d))))
def calc(n, c, d):
    return n-(n / c +
              n / d - n / (c * d / math.gcd(c, d)))


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

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


if __name__ == "__main__":
    main()


import math



#     return n-(math.floor(n / c) +
#               math.floor(n / d) - math.floor(n / (c * d / math.gcd(c, d))))
def calc(n, c, d):
    return n-(n // c +
              n // d - n // (c * d // math.gcd(c, d)))


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

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


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# coding: UTF-8
import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *
import fractions
readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

a, b, c, d = readmi()

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
t1 = b // c - (a - 1) // c
t2 = b // d - (a - 1) // d
ans = t1 + t2
l = lcm(c, d)
if b >= l >= a:
    ans -= b // l - (a - 1) // l
print(b - a + 1 - ans)

# coding: UTF-8
import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *
readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

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

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

a, b, c, d = readmi()
t1 = b // c - (a - 1) // c
t2 = b // d - (a - 1) // d
l = lcm(c, d)
t3 = 0
t3 = b // l - (a - 1) // l
k = t1 + t2 - t3
print(b - a + 1 - k)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from math import gcd
from decimal import Decimal as dec 
a, b, c, d = map(dec,input().split())
if a % c ==0:
    c_explicit = b // c - a // c + 1
else:
    c_explicit = b // c - a // c 
if a % d ==0:
    d_explicit = b // d - a // d + 1
else:
    d_explicit = b // d - a // d 
e = gcd(int(c), int(d))
e = dec(e)
gcl = (c / e) * (d / e) * e
if a % gcl ==0:
    e_explicit = b // gcl - a // gcl + 1
else:
    e_explicit = b // gcl - a // gcl 
print(c_explicit, d_explicit, e_explicit, gcl)
g = b - a + 1 - c_explicit - d_explicit + e_explicit
print(g)

from math import gcd
a, b, c, d = map(int,input().split())
if a % c ==0:
    c_explicit = b // c - a // c + 1
else:
    c_explicit = b // c - a // c 
if a % d ==0:
    d_explicit = b // d - a // d + 1
else:
    d_explicit = b // d - a // d 
e = gcd(c, d)
gcl = (c / e) * (d / e) * e
if a % gcl ==0:
    e_explicit = b // gcl - a // gcl + 1
else:
    e_explicit = b // gcl - a // gcl 
print(c_explicit, d_explicit, e_explicit, gcl)
g = b - a + 1 - c_explicit - d_explicit + e_explicit
print(int(g))

from math import gcd
a, b, c, d = map(int,input().split())
c_explicit = b // c - (a - 1)// c 
d_explicit = b // d - (a - 1)// d
e = gcd(c, d)
gcl = c * d / e
e_explicit = b // gcl - (a - 1)// gcl
g = b - a + 1 - c_explicit - d_explicit + e_explicit
print(g)


from math import gcd as gcd
a, b, c, d = map(int,input().split())

s = gcd(c, d)
p = c * d // s
divide_c = b // c - (a - 1) // c
divide_d = b // d - (a - 1) // d
divide_cd = b // p - (a - 1) // p
print(int(b - a + 1 - divide_c - divide_d + divide_cd))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted