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: Runtime Error

Solution code:
import math
A,B,C,D = map(int,input().rstrip().split(' '))
x = (B // C) - ((A-1) // C)
y =  (B // D) - ((A-1) // D)
E = (C * D) // math.gcd(C,D)
z = (B // E) - ((A-1) // E)
print((B-A+1)-(x+y-z))

Submission status: Runtime Error

Solution code:
from math import gcd

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

def not_devision(a, x, y):
    return (a - (a//x)) + (a - (a//y)) - (a - (a//((x*y)//gcd(x, y))))

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

Submission status: Runtime Error

Solution code:
import math

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

c1=B//C
c2=(A-1)//C

cd1=B//((C*D)/math.gcd(C,D))
cd2=(A-1)//((C*D)/math.gcd(C,D))

d1=B//D
d2=(A-1)//D


print(int(B-A+1-(c1-c2)-(d1-d2)+(cd1-cd2)))

Submission status: Runtime Error

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

C_s = (A-A%C)//C
C_e = (B-B%C)//C

D_s = (A-A%D)//D
D_e = (B-B%D)//D

C_cnt = C_e - C_s
if A%C==0:
    C_cnt += 1
D_cnt = D_e - C_s
if A%C==0:
    D_cnt += 1

import math
lcm = (C * D) // math.gcd(C, D)

lcm_s = (A-A%lcm)//lcm
lcm_e = (B-B%lcm)//lcm

lcm_cnt = lcm_e - lcm_s
if A%lcm==0:
    lcm_cnt += 1

cnt = C_cnt + D_cnt - lcm_cnt
ans = B - A + 1 - cnt
print(ans)

Submission status: Runtime Error

Solution code:
import os, sys, re, math

A,B,C,D = [int(s) for s in input().split(' ')]

lcm = C * D // math.gcd(C, D)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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


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

c = lcm(c, d)


"""
B = 0
B += b//c
B += b//d
B -= b//lcm(c, d)

A = 0
A += a//c
A += a//d
A -= a//lcm(c, d)

ans = (b-a+1) - (B - A + (a%c == 0 or a%d == 0))
print(ans)
"""
print(c)

Submission status: Runtime Error

Solution code:
from math import gcd
a,b,c,d=list(map(int,input().split()))
if b<c:
    total=0
    print(b-a+1)
    exit()
if c>=a:
    first=c
else:
    first=(a//c +1)*c
last=b-b%c
total_fac_of_c=(last-first)//c + 1
#print(total_fac_of_c)
if d>=a:
    first=d
else:
    first=(a//d + 1)*d
last=b-b%d
total_fac_of_d=(last-first)//d + 1
#print(total_fac_of_d)
h=(a*b)//(gcd(a,b))
#print(h)
if h>=a:
    first=h
else:
    first=(a//h + 1)*h
last=b-b%h

total_fac_of_h=(last-first)//h + 1
#print(total_fac_of_h)

print(b-a+1-(total_fac_of_c+total_fac_of_d-total_fac_of_h))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math


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


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

def comp(number, a_n, b_n):
    return number - (number // a_n + number // b_n - number // lcm(a, b))

print(int(comp(b, c, d) - comp(a, c, d)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math
n=input().rstrip().split(" ")
for i in range(4):
    n[i]=int(n[i])
toc=(n[0]%n[2])
tod=(n[0]%n[3])
tocd=(n[0]%(n[2]*n[3]//math.gcd(n[2],n[3])))
#print(toc)
#print(tod)
#print(tocd)
d=n[1]-n[0]+1
ans=[d-((d+toc)//n[2]),d-((d+tod)//n[3]),d-((d+tocd)//((n[2]*n[3]//math.gcd(n[2],n[3]))))]
#print(ans)
print(ans[0]+ans[1]-ans[2])

Submission status: Runtime Error

Solution code:
import math

A, B, C, D = map(int, input().split())
E = (C * D) // math.gcd(C, D)
# print(E)
num_c = B // C - A // C + (1 if A % C == 0 else 0)
num_d = B // D - A // D + (1 if A % D == 0 else 0)
num_e = B // E - A // E + (1 if A % E == 0 else 0)
# print(num_c)
# print(num_d)
# print(num_e)
num = B - A + 1 - (num_c + num_d - num_e)
print(num)

Submission status: Runtime Error

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

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

def f(a,b,c):
    return (b - a + 1) // c + (1 if b % c <= a % c else 0)

if c != 1 and d != 1:
    if c != d:
        print ((b-a+1) - (b // c - ceil(a / c) + 1) - (b // d - ceil(a / d) + 1) + (b // lcm(c, d) - ceil(a / lcm(c, d)) + 1))
    else:
        print ((b - a + 1) - f(a, b, c))
else:
    print (0)

Submission status: Runtime Error

Solution code:
import math

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

# cの倍数の数
cCount = math.floor(b / c) - math.ceil(a / c) + 1
dCount = math.floor(b / d) - math.ceil(a / d) + 1

lcm = int(c * d / math.gcd(c, d))
lcmCount = math.floor(b / lcm) - math.ceil(a / lcm) + 1

print(b - a + 1 - (cCount + dCount - lcmCount))

Submission status: Runtime Error

Solution code:

import math

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

ans = b - a + 1 

if d%c == 0:#4 8 4 2
    ans -= b//c - a//c + (0 if a%c != 0 else 1)

else:
    x = b // c - a//c + (0 if a%c != 0 else 1)
    y = b // d - a//d + (0 if a%d != 0 else 1)

    lcm = c*d//math.gcd(c,d)
    t = b //lcm - a//lcm + (1 if a >= lcm and a%lcm ==0 else 0)

    ans = ans -x-y+t
#    print(x,y,t,lcm,ans)

#    ans += t 


print(ans)

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int, input().split())
sub=b-a
tmpc=sub//c
tmpd=sub//d
import fractions
def lcm(x,y):
    return (x*y) // fractions.gcd(x,y)
tmplcm=sub//lcm(c,d)
print(max(sub-(tmpc+tmpd-tmplcm)), 0)

Submission status: Runtime Error

Solution code:
import math

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

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

Submission status: Runtime Error

Solution code:
import math

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

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

AdivisibleC = (A - 1) // C
AdivisibleD = (A - 1) // D
AdivisibleCD = (A - 1) // lcm(C, D)
AindivisibleCD = (A - 1) - (AdivisibleC + AdivisibleD - AdivisibleCD)

BdivisibleC = B // C
BdivisibleD = B // D
BdivisibleCD = B // lcm(C, D)
BindivisibleCD = B - (BdivisibleC + BdivisibleD - BdivisibleCD)

print(BindivisibleCD - AindivisibleCD)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

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

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

CD = C * D / math.gcd(C, D)
cd = int(B/CD) - int((A-1)/CD)

ans = B - (A-1) - (c + d - cd)
ans = int(ans)

print(ans)

Submission status: Runtime Error

Solution code:
import math


class AntiDivision:
    def __init__(self):
        self.A, self.B, self.C, self.D = map(int, input().split())

    def cal(self):
        a_b_count = self.B - self.A + 1
        lcm = (self.C * self.D) // math.gcd(self.C, self.D)
        c_count = self.B // self.C - (self.A - 1) // self.C
        d_count = self.B // self.D - (self.A - 1) // self.D
        lcm_count = self.B // lcm - (self.A - 1) // lcm

        print(a_b_count - c_count - d_count + lcm_count)


antiDivision = AntiDivision()
antiDivision.cal()

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
import math
def lcm(x,y):
    return(x*y)//math.gcd(x,y)
e=lcm(c,d)    
ans=(b-a+1)-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//e-(a-1)//e)
print(ans)

Submission status: Runtime Error

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

ans = 0

c_n_min = math.ceil(A / C)
c_n_max = math.floor(B / C)
c_n = c_n_max - c_n_min + 1

d_n_min = math.ceil(A / D)
d_n_max = math.floor(B / D)
d_n = d_n_max - d_n_min + 1

cd = C * D /math.gcd(C,D)
cd_n_min = math.ceil(A / cd)
cd_n_max = math.floor(B / cd)
cd_n = cd_n_max - cd_n_min + 1

ans = (B - A + 1) - (c_n + d_n - cd_n)
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
import math

def count_div(a, b, div):
    ac = a // div
    if ac * div < a:
        ac += 1
    bc = b // div
    if bc * div > b:
        bc -= 1
    return bc - ac + 1

if __name__ == '__main__':
    A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()]

    nc = count_div(A, B, C)
    
    nd = count_div(A, B, D)
    
    CD = int(C * D / math.gcd(C, D))
    ncd = count_div(A, B, CD)
    
    n = B - A + 1
    
    ans = n - (nc + nd - ncd)
    print(ans)

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = map(int, input().split())
diff = B - A + 1
count_c = int(B/C) - int((A-1)/C)
count_d = int(B/D) - int((A-1)/D)
cd = (C*D) // math.gcd(C,D)
count_cd = int(B/cd) - int((A-1)/cd)
print(diff - count_c - count_d + count_cd)

Submission status: Runtime Error

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

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

def f(a,b,c):
    return (b - a + 1) // c + (1 if b % c <= a % c else 0)

if c != 1 and d != 1:
    if c != d:
        print ((b-a+1) - f(a,b,c) - f(a,b,d) + f(a,b,lcm(c,d)))
    else:
        print ((b - a + 1) - f(a, b, c))
else:
    print (0)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)
from math import gcd

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

def main():
    A, B, C, D = [int(c) for c in input().split()]
    N_U = (B) - (A - 1)
    N_C = B // C - (A - 1) // C
    N_D = B // D - (A - 1) // D
    N_C_D = int(B // lcm(C, D) - (A - 1) // lcm(C, D))
    excluded_N_C_D = N_C + N_D - N_C_D
    print(int(N_U - excluded_N_C_D))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

from math import gcd
c_d=c*d/gcd(c,d)
wari_c=int(b//c-a//c)
wari_d=int(b//d-a//d)
wari_c_d=int(b//c_d-a//c_d)

print(b-a+1-(wari_c+wari_d-wari_c_d))

Submission status: Runtime Error

Solution code:
import math

#a,b,c,d = map(int,input().split())
li = input().split()
a = int(li[0])
b = int(li[1])
c = int(li[2])
d = int(li[3])

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

B = 0
B += b//c
B += b//d
B -= b//lcm(c, d)

A = 0
A += a//c
A += a//d
A -= a//lcm(c, d)

ans = (b-a+1) - (B - A + (a%c == 0 or a%d == 0))
print(ans)

Submission status: Runtime Error

Solution code:
import math
from fractions import gcd

def number_calc(A,B,x):
    left = math.ceil(A/x)
    right = math.floor(B/x)
    res = max(right-left+1,0)
    return res

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

ans = B-A+1
ans -=number_calc(A,B,C)
ans -=number_calc(A,B,D)
ans +=number_calc(A,B,(C*D)/math.gcd(C,D))

print(ans)

Submission status: Runtime Error

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

n = B//C
m = (A-1)//C
p = B//D
q = (A-1)//D
x = B//(C*D// math.gcd(C,D))
y = (A-1)//(C*D// math.gcd(C,D))
L = (B-A+1)-((n-m)+(p-q)-(x-y))
print(L)

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
e=lcm(c,d)    
ans=(b-a+1)-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//e-(a-1)//e)
print(ans)

Submission status: Runtime Error

Solution code:
from math import *
from fractions import *
a,b,c,d=map(int,input().split())
lcm=lambda x,y: x*y//gcd(x,y)

def f(a,b,c):
    return (b - a + 1) // c + (1 if b % c <= a % c else 0)

if c != 1 and d != 1:
    if c != d:
        print (b-a+1) - f(a,b,c) - f(a,b,d) + f(a,b,lcm(c,d))
    else:
        print (b - a + 1) - f(a, b, c)
else:
    print 0

Submission status: Runtime Error

Solution code:
from math import gcd


def main():
    A, B, C, D = map(int, input().split())
    Q_AC, R_AC = A // C, A % C
    Q_AD, R_AD = A // D, A % D
    Q_BC, R_BC = B // C, B % C
    Q_BD, R_BD = B // D, B % D
    Q_ACD, R_ACD = A // lcm(C, D), A % lcm(C, D)
    Q_BCD, R_BCD = B // lcm(C, D), B % lcm(C, D)
    N_C = num_baisu(Q_AC, Q_BC, R_AC, R_BC)
    N_D = num_baisu(Q_AD, Q_BD, R_AD, R_BD)
    N_CD = num_baisu(Q_ACD, Q_BCD, R_ACD, R_BCD)
    print(B - A + 1 - (N_C + N_D - N_CD))
    return


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


def num_baisu(Q_A, Q_B, R_A, R_B):
    if R_A == 0 and R_B == 0:
        return Q_B - Q_A + 1
    elif R_A == 0 and R_B != 0:
        return Q_B - Q_A + 1
    elif R_A != 0 and R_B == 0:
        return Q_B - (Q_A + 1) + 1
    else:
        return Q_B - (Q_A + 1) + 1


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

e=math.floor(b/c)
f=math.ceil(a/c)

ans=e-f+1

g=math.floor(b/d)
h=math.ceil(a/d)

ans=ans+g-h+1

i=(c*d)//math.gcd(c,d)

j=math.floor(b/i)
k=math.ceil(a/i)

ans=ans-(j-k+1)

print(b-a+1-ans)

Submission status: Runtime Error

Solution code:
def acinput():
    return list(map(int,input().split(" ")))


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

a,b,c,d=acinput()


l=lcm(c,d)
CD=int(b/l)-int((a-1)/l)
nC=int(b/c)-int((a-1)/c)
nD=int(b/d)-int((a-1)/d)

print(int(b-a+1-(nC+nD-CD)))

Submission status: Runtime Error

Solution code:
import math
def lcm(a, b):
  return (a * b) // math.gcd(a, b)
input = list(map(int, input().split(' ')))
total_count = input[1] + 1 - input[0]
div_c = math.floor(input[1] / input[2]) - math.floor(input[0] / input[2])
if input[0] % input[2] == 0:
  div_c += 1
div_d = math.floor(input[1] / input[3]) - math.floor(input[0] / input[3])
if input[0] % input[3] == 0:
  div_d += 1
div_cd = math.floor(input[1] / lcm(input[2], input[3])) - math.floor(input[0] / lcm(input[2], input[3]))
if input[0] % lcm(input[2], input[3]) == 0:
  div_cd += 1
print(total_count - (div_c + div_d - div_cd))

Submission status: Runtime Error

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

c_div = int(b / c) - int((a - 1) / c)
d_div = int(b / d) - int((a - 1) / d)
lcm = int(c * d / math.gcd(c, d))
common = int(b / (lcm)) - int((a - 1) / (lcm))

print(b - a + 1 - c_div - d_div + common)

Submission status: Runtime Error

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

a,b,c,d=(int(x) for x in input().split())
bs=lcm(c,d)
kihon=bs+1-(bs/c)-(bs/d)
saisyo=((a//bs)+1)*bs
saidai=(b//bs)*bs
count=kihon*(saidai-saisyo)/bs
ans=saisyo-a-(((saisyo-a)//c)+((saisyo-a)//d))+b-saidai-(((b-saidai)//c)+((b-saidai)//d))
print(math.floor(ans+count))

Submission status: Runtime Error

Solution code:

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

#N = int(input())

#list(map(int,input().split()))

cnt = B-A+1

import math
E = C*D / math.gcd(C, D)


A_C = A//C
A_dC = A%C

B_C = B//C
#B_dC = B%C

A_D = A//D
A_dD = A%D

B_D = B//D
#B_dD = B%D

A_E = A//E
A_dE = A%E

B_E = B//E
#B_dE = B%E

C_cnt = B_C - A_C
if A_dC == 0:
    C_cnt += 1
D_cnt = B_D - A_D
if A_dD == 0:
    D_cnt += 1
E_cnt = B_E - A_E
if A_dE == 0:
    E_cnt += 1  

ans = cnt - C_cnt - D_cnt + E_cnt
print(int(ans))

Submission status: Runtime Error

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

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

B = 0
B += b//c
B += b//d
B -= b//lcm(c, d)

A = 0
A += a//c
A += a//d
A -= a//lcm(c, d)

ans = (b-a+1) - (B - A + (a%c == 0 or a%d == 0))
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

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

c = (B  - B%C) / C - ((A-1)  - (A-1)%C)/C
d = (B  - B%D) / D - ((A-1)  - (A-1)%D)/D

CD = (C * D  - (C * D % math.gcd(C, D))) / math.gcd(C, D)
cd = (B  - B%CD) / CD - ((A-1)  - (A-1)%CD)/CD

ans = B - (A-1) - (c + d - cd)
ans = int(ans)

print(ans)

Submission status: Runtime Error

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

lcm = (c * d) // math.gcd(c, d)

Cstart = a - (a % c) + c if a % c != 0 else a
Cend = b - (b % c)
Dstart = a - (a % d) + d if a % d != 0 else a
Dend = b - (b % d)
LCMstart = a - (a % lcm) + lcm if a % lcm != 0 else a
LCMend = b - (b % lcm)

# print(Cstart, Cend)
# print(Dstart, Dend)
# print(LCMstart, LCMend)
# print()

Ccnt, Dcnt, LCMcnt = 0, 0, 0
if Cstart <= Cend:
	Ccnt = (Cend - Cstart) // c + 1
if Dstart <= Dend:
	Dcnt = (Dend - Dstart) // d + 1
if LCMstart <= LCMend:
	LCMcnt = (LCMend - LCMstart) // lcm + 1

# print(Ccnt, Dcnt, LCMcnt)
# print((Cend - Cstart)//4, Ccnt)

print((b-a+1) - Ccnt - Dcnt + LCMcnt)

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = map(int, input().split())
ans = b - a + 1
lcm = c * d // math.gcd(c, d)
def calc(d):
    global a, b
    c1 = (a - 1) // d
    c2 = b // d
    return c2 - c1
print(ans - calc(c) - calc(d) + calc(lcm))

Submission status: Runtime Error

Solution code:
A, B, C, D = map(int, input().split())
num_list = list(range(A, B+1))
C_start = int(A/C)
C_end = int(B/C)
D_start = int(A/D)
D_end = int(B/D)
for i in range(C_start, C_end+1):
    try:
        num_list.remove(i*C)
    except ValueError:
        pass
for j in range(D_start, D_end+1):
    try:
        num_list.remove(j*D)
    except ValueError:
        pass
print(len(num_list))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A,B,C,D = map(int,input().split())
import math
E = gcd(C,D)
r = int(B/C) + int(B/D) - int(B/E) - int(A-1/C) + int(A-1/D) + int(A-1/D)
print(r)

Submission status: Runtime Error

Solution code:
s, n, c, d = map(int, input().split())
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in [c, d]:
    if not is_prime[i]:
        continue
    for j in range(i * 2, n + 1, i):
        is_prime[j] = False
print(is_prime[s: n + 1].count(True))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
s=b-a
bc=b//c
if a%c==0:
    ac=a//c-1
else:
    ac=a//c
bd=b//d
if a%d==0:
    ad=a//d-1
else:
    ad=a//d
gcd=math.gcd(c,d)
l=c*d/gcd
bl=b//l
if a%l==0:
    al=a//l-1
else:
    al=a//l
print(int(b-a+1-(bc-ac+bd-ad-bl+al)))

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = map(int, input().split())
num = b-a+1
if a%c ==0:
        num1 = int(a/c)-1
else:
        num1 = int(a/c)
num2 = int(b/c)
numc = num2-num1
if a%d ==0:
        num3 = int(a/d) -1
else:
        num3 = int(a/d)
num4 = int(b/d)
numd = num4-num3
num_new = int((c*d)/math.gcd(c, d))
if a%num_new == 0:
        num5 = int(a/num_new)-1
else:
        num5 = int(a/num_new)
num6 = int(b/num_new)
numcd = num6-num5
print(num - numc - numd + numcd)

Submission status: Runtime Error

Solution code:
# coding: utf-8

import math
import sys
def input(): return sys.stdin.readline().strip()

# N = int(input())
# L = [int(x) for x in input().split()]
A, B, C, D = map(int, input().split())
# S = input()

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


def kosu(n, p):
    return n // p

x = kosu(B, C) - kosu(A - 1, C)
y = kosu(B, D) - kosu(A - 1, D)
z = kosu(B, lcm(C, D)) - kosu(A - 1, lcm(C, D))

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

Submission status: Runtime Error

Solution code:
A, B, C, D = map(int, input().split())
ans = set(list(range(A, B+1)))


for i in range(A//C + 1, B //C + 1):
    if i*C in ans:
        ans.remove(i*C)

for i in range(A//D + 1, B //D + 1):
    if i*D in ans:
        ans.remove(i*D)
    


print(len(ans))

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int, input().split())
sub=b-a
tmpc=sub//c
tmpd=sub//d

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

tmplcm=sub//lcm(c,d)
print(sub-(tmpc+tmpd-tmplcm))

Submission status: Runtime Error

Solution code:
def acinput():
    return list(map(int,input().split(" ")))


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

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

a,b,c,d=acinput()


l=lcm(c,d)
n_CandD=int(b/l)-int((a-1)/l)
n_C=int(b/c)-int((a-1)/c)
n_D=int(b/d)-int((a-1)/d)

print(int(b-a+1-(n_C+n_D-n_CandD)))

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
    
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

def main():
    a,b,c,d = LI()
    c_d_gcd = lcm(c,d)
    s = b//c + b//d - b//c_d_gcd
    t = (a-1) // c + (a-1) // d - (a-1) // c_d_gcd
    print(b - a + 1 - (s-t))
main()

Submission status: Runtime Error

Solution code:
import math

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

A, B, C, D = [int(i) for i in input().split()]

C_count = math.floor(B/C) - math.ceil(A/C) + 1
D_count = math.floor(B/D) - math.ceil(A/D) + 1
both_count = math.floor(B/lcm(C, D)) - math.ceil(A/lcm(C, D)) + 1
# print(C_count)
# print(D_count)
# print(both_count)
answer = B - A + 1 - (C_count + D_count - both_count)
print(answer)

Submission status: Runtime Error

Solution code:
from math import *
from fractions import *
a,b,c,d=map(int,raw_input().split())
lcm=lambda x,y: x*y//gcd(x,y)

print(b-a+1 - ((b-a+1)//c + (b-a+1)//d - (b-a+1)//lcm(c,d)))

Submission status: Runtime Error

Solution code:
# import numpy as np
import math

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

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

def undivided_under(N, C, D):
    dived_C = N // C
    dived_D = N // D
    dived_lcm = N // lcm(C, D)

    # print(dived_C, dived_D, dived_lcm)

    return(N - dived_C - dived_D + dived_lcm)

# print(A,B,C,D)
# print(undivided_under( B, C, D ))
# print(undivided_under( A-1, C, D ))

print( int( undivided_under(B, C, D) - undivided_under(A-1, C, D)) )

Submission status: Runtime Error

Solution code:
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)))

Submission status: Runtime Error

Solution code:
from math import gcd

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

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

m = (int(b // c) - int((a - 1) // c)) + (int(b // d) - int((a - 1) // d)) - (int(b // l) - int((a - 1) // l))

print(int(b - a + 1 - m))

Submission status: Runtime Error

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

c_left = [a // c - 1, a // c][a % c != 0]
c_right = b // c

c_number = c_right - c_left

d_left = [a // d - 1, a // d][a % d != 0]
d_right = b // d

d_number = d_right - d_left
cdgcd = (c * d) // fractions.gcd(c, d)

cd_left = [a // (cdgcd - 1), a // (cdgcd)][a % (cdgcd) != 0]
cd_right = b // (cdgcd)

cd_number = cd_right - cd_left

print(b - a + 1 -  (c_number + d_number - cd_number))

Submission status: Runtime Error

Solution code:
import sys
import math

def main():
    # a = sys.stdin.readline().strip()
    a, b, c, d = [int(i) for i in sys.stdin.readline().strip().split()]
    # [[int(i) for i in sys.stdin.readline().strip().split()] for _ in range(2)]
    n = b - a + 1
    # print(n)
    if a % c == 0:
        mi_c = a // c
    else:
        mi_c = a // c + 1
    ma_c = b // c
    n -= (ma_c - mi_c + 1)
    # print(ma_c, mi_c, n)

    if a % d == 0:
        mi_d = a // d
    else:
        mi_d = a // d + 1
    ma_d = b // d
    n -= (ma_d - mi_d + 1)
    # print(ma_d, mi_d, n)

    cd = (c * d) // math.gcd(c, d)
    if a % cd == 0:
        mi_cd = a // cd
    else:
        mi_cd = a // cd + 1
    ma_cd = b // cd
    n += (ma_cd - mi_cd + 1)
    # print(ma_cd, mi_cd, n)
    print(n)
    
main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import fractions

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

ans = 0

Cans = fractions.floor(B/C) - fractions.ceil(A/C) + 1
Dans = fractions.floor(B/D) - fractions.ceil(A/D) + 1

CD = C * D / fractions.gcd(C,D)
CDans = fractions.floor(B/CD) - fractions.ceil(A/CD) + 1

ans = (B-A+1) - (Cans + Dans - CDans)

print(ans)

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
    
def lcm(x, y):
    return (x * y) // math.gcd(x, y)


def main():
    a,b,c,d = LI()
    c_d_gcd = lcm(c,d)
    s = b//c + b//d - b//c_d_gcd
    t = (a-1) // c + (a-1) // d - (a-1) // c_d_gcd
    print(b - a + 1 - (s-t))
main()

Submission status: Runtime Error

Solution code:
import math
import sys

input = sys.stdin.readline


def main():
    A, B, C, D = [int(i) for i in input().split()]
    # X : AとBの間の整数の数
    X = B - A + 1
    # Y : AとBの間でCの倍数の数
    Y = (B // C) - ((A - 1) // C)
    # Z : AとBの間でDの倍数の数
    Z = (B // D) - ((A - 1) // D)
    # V : CとDの最小公倍数
    V = (C * D) // math.gcd(C, D)
    # W : AとBの間でVの倍数の数
    W = (B // V) - ((A - 1) // V)
    print(X - Y - Z + W)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int, input().split())
# for i , a<i<b, i % c|d != 0
sub=b-a
tmpc=sub//c
tmpd=sub//d
import math
def lcm(a,b):
    return (a*b) // math.gcd(a,b)
tmplcm=sub//lcm(c,d)
print(sub-(tmpc+tmpd-tmplcm))

Submission status: Runtime Error

Solution code:
import numpy as np
import math

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

c = (B  - B%C) / B - ((A-1)  - (A-1)%C)/C
d = (B  - B%D) / B - ((A-1)  - (A-1)%D)/D

CD = (C * D  - (C * D % math.gcd(C, D))) / math.gcd(C, D)
cd = (B  - B%CD) / B - ((A-1)  - (A-1)%CD)/CD

ans = B - (A-1) - (c + d - cd)
ans = int(ans)

print(ans)

Submission status: Runtime Error

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

a,b,c,d=(int(x) for x in input().split())
bs=lcm(c,d)
kihon=bs+1-(bs/c)-(bs/d)
saisyo=((a//bs)+1)*bs
saidai=(b//bs)*bs
count=kihon*(saidai-saisyo)/bs
ans=saisyo-a-(((saisyo-a)//c)+((saisyo-a)//d))+b-saidai-(((b-saidai)//c)+((b-saidai)//d))
print(math.floor(ans+count))

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = map(int, input().split())
E=C*D//math.gcd(C,D)
total=0
if A%C==0:
    total += B//C-(A)//C+1
else:
    total += B // C - (A) // C

if A%D==0:
    total += B//D-(A-1)//D+1
else:
    total += B // D - (A - 1) // D

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

print(B-A+1-total)

Submission status: Runtime Error

Solution code:
import math

A, B, C, D = list(map(int, input().split()))
C_mult = (B // C) - ((A-1) // C)
D_mult = (B // D) - ((A-1) // D)

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

inter = (B // E) - ((A-1) // E)
whole = B - A + 1
print(whole - C_mult - D_mult + inter)

Submission status: Runtime Error

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

c_left = [a // c - 1, a // c][a % c != 0]
c_right = b // c

c_number = c_right - c_left

d_left = [a // d - 1, a // d][a % d != 0]
d_right = b // d

d_number = d_right - d_left
cdgcd = int(c * d / fractions.gcd(c, d))

cd_left = [a // (cdgcd - 1), a // (cdgcd)][a % (cdgcd) != 0]
cd_right = b // (cdgcd)

cd_number = cd_right - cd_left


print(b - a + 1 -  (c_number + d_number - cd_number))

Submission status: Runtime Error

Solution code:
import math

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

lcm = int(c * d / math.gcd(c, d))

bb = int((b // c) + (b // d) - (b // lcm))

aa = int(((a-1) // c) + ((a-1) // d) - ((a-1) // lcm))

print(bb, aa)

print((b-a) - int(bb-aa) + 1)

Submission status: Runtime Error

Solution code:
import math
def acinput():
    return list(map(int,input().split(" ")))

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

a,b,c,d=acinput()


l=lcm(c,d)
n_CandD=int(b/l)-int((a-1)/l)
n_C=int(b/c)-int((a-1)/c)
n_D=int(b/d)-int((a-1)/d)

print(int(b-a+1-(n_C+n_D-n_CandD)))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
lcm = int(c*d/math.gcd(c,d))
def num(x):
    return(b//x-(a-1)//x)
ans = (b-a+1)-num(c)-num(d)+num(lcm)
print(int(ans))

Submission status: Runtime Error

Solution code:
import sys, fractions

readline = sys.stdin.readline

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

c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
lcm = C * D // fractions.gcd(c, d)
cd = B // lcm - (A - 1) // lcm

ans = B - (A - 1) - (c + d - cd)

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

start = A // C
end = B // C
if A % C != 0:
    start = start + 1
C_num = end - start + 1

start = A // D
end = B // D
if A % D != 0:
    start = start + 1
D_num = end - start + 1

CD = C * D // math.gcd(C, D)
start = A // CD
end = B // CD
if A % CD != 0:
    start = start + 1
CD_num = end - start + 1

ans = (B - A + 1) - (C_num + D_num - CD_num)

print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
from sys import stdin
import sys, math
import numpy as np

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


a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
#print(a, b, c, d)
#bまでで3で割り切れる数
three_all = b // c
#a-1までで3で割り切れる数
three_less = (a-1) // c
three_range = three_all - three_less
    
two_all = b // d
two_less = (a-1) // d
two_range = two_all - two_less
    
z = lcm(c,d)
six_all = b // z
six_less = (a-1) // z
six_range = six_all - six_less
    
num = three_range + two_range - six_range
    
ans = b-a+1-num
print(ans)

Submission status: Runtime Error

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

k = B - A + 1

if A%C == 0:
    sc = B//C -A//C +1
else:
    sc = B//C -A//C

if A%D == 0:
    sd = B//D -A//D +1
else:
    sd = B//D -A//D    
    

cd = C*D/math.gcd(C,D)

if A%D == 0:
    scd = B//cd -A//cd +1
else:
    scd = B//cd -A//cd    

print(int(k + scd -sc -sd))

Submission status: Runtime Error

Solution code:
from math import gcd

def debug(*args):
    import sys
    #print(*args, file=sys.stderr)

def solve(A, B, C, D):
    L = C * D // gcd(C, D)
    A-=1
    debug("A=%d, B=%d, C=%d, D=%d" %(A,B,C,D))
    debug((B//C, A//C), (B//D, A//D) , (B//L , A//L))
    debug((B//C - A//C), (B//D - A//D) , (B//L - A//L))
    return B-A- ((B//C - A//C) + (B//D - A//D) - (B//L - A//L))

def main():
    A, B, C, D = [int(x) for x in input().split()]
    print(solve(A, B, C, D))
    pass

main()