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 math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Bad")
    elif q == 0:print("Good")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

#n = ip()                                     #入力整数1つ
a,b,c,d= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(m)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
sub1 = (b+1)//d - a//d
sub2 = (b+1)//c - a//c
inter = lcm(c,d)
sub3 = (b+1)//inter - a//inter
print(b-a-sub1-sub2+sub3+1)

Submission status: Wrong Answer

Solution code:
import math
import os
import sys
from fractions import gcd

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

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


def count(n):
    st = math.ceil(A / n)
    en = math.floor(B / n)
    return max(0, en - st + 1)


print(B - A + 1 - (count(C) + count(D) - count(C * D // gcd(C, D))))

Submission status: Wrong Answer

Solution code:
import fractions

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

A, B, C, D = list(map(int, input().split()))
NC = B // C - A // C
if A % C == 0:
  NC += 1
ND = B // D - A // D
if A % D == 0:
  ND += 1
LCM = lcm(C, D)
NCA = B // LCM - A // LCM
TOTAL = B - A + 1
NOTN = NC+ND-NCA
print (TOTAL - NOTN)

Submission status: Wrong Answer

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

diffs = B - A

C_num = (diffs - (A % C)) // C
D_num = (diffs - (A % D)) // D
sum_num = (diffs - (A % (D * C))) // (C * D)


print(diffs - (C_num + D_num - sum_num))

Submission status: Wrong Answer

Solution code:
def main():
    def f(n, c, d):
        return n // c + n // d - n // (c * d)
    a, b, c, d = map(int, input().split())
    print(b - a + 1 -  f(b, c, d) + f(a - 1, c, d))
    return 0

main()

Submission status: Wrong Answer

Solution code:
import math
import os
import sys
from fractions import gcd

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

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


def count(n):
    st = math.ceil(A / n)
    en = math.floor(B / n)
    print(n, st, en)
    return max(0, en - st + 1)


print(B - A + 1 - (count(C) + count(D) - count(C * D // gcd(C, D))))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right; from collections import Counter, defaultdict, deque, OrderedDict; from copy import deepcopy; from fractions import gcd; from functools import lru_cache, reduce; from math import ceil, floor; from sys import stdin, setrecursionlimit
import heapq as hq; import itertools as its; import operator as op


# globals
inf = float('inf')
input = stdin.readline


def main():
    a, b, c, d = get_li()
    c_min = (a + c - 1) // c
    c_max = b // c
    if c == d:
        print(b - a + 1 - (c_max - c_min + 1))
        return
    d_min = (a + d - 1) // d
    d_max = b // d
    e = c * d // gcd(c, d)
    if c == e or d == e:
        print(b - a + 1 - (c_max - c_min + 1) - (d_max - d_min + 1))
        return
    e_min = (a + e - 1) // e
    e_max = b // e
    print(b - a + 1 - (c_max - c_min + 1) - (d_max - d_min + 1) + (e_max - e_min + 1))
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    setrecursionlimit(4100000)
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:


(A,B,C,D) = (int(i) for i in input().split(" "))
c = C
d = D
if c > d:
	d += c
	c = d-c
	d = d-c
while d%c!=0:
	d = d%c
	d += c
	c = d-c
	d = d-c
E = C*D/c
print(B-A+1-int(B/C)+int((A-1)/C)-int(B/D)+int((A-1)/D)+int(B/E)-int((A-1)/E))

Submission status: Wrong Answer

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

def calc(x, k):
    return x // k


def all_calc(x):
    return x - calc(x, c) + calc(x, d) - calc(x, c * d // gcd(c, d))
print(all_calc(b) - all_calc(a - 1))

Submission status: Wrong Answer

Solution code:
import fractions
def LCM(a,b):
    return int(a*b/fractions.gcd(a,b))
A,B,C,D = map(int,input().split())#A以上B以下
L = LCM(C,D)
Cbaisu = B//C - A//C
Dbaisu = B//D - A//D
Lbaisu = B//L - A//L
print(B-A+1 - Cbaisu - Dbaisu + Lbaisu)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def calc(x, k):
    return x // k


def all_calc(x):
    return x - int(calc(x, c) + calc(x, d) - calc(x, c * d / gcd(c, d)))
print(all_calc(b) - all_calc(a - 1))

Submission status: Wrong Answer

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

hogeb = B // D
hogec = B // C
hogebc = B // (D * C)

hoge = B-(hogeb + hogec -hogebc)

ononb = A // D
ononc = A // C
ononbc = A // (D * C)

onon = A-(ononb + ononc - ononbc)

print(hoge-onon)

Submission status: Wrong Answer

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

hogeb = B // D
hogec = B // C
hogebc = B // (D * C)

hoge = hogeb + hogec -hogebc

ononb = A // D
ononc = A // C
ononbc = A // (D * C)

onon = ononb + ononc - ononbc

print(hoge-onon)

Submission status: Time Limit Exceeded

Solution code:
a=input('').split()
a=list(map(int,a))
b=(a[0])
c=(a[1])
d=(a[2])
e=(a[3])
f=0

while b<=c:
     if b%d>0 and b%e>0:
        f=f+1
     b=b+1
print(f)

Submission status: Time Limit Exceeded

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

# CでもDでも割り切れない = 全体(a) - Cで割り切れる(b) + Dで割り切れる(c) + CでもDでも割り切れる(d)
lcm = C*D // math.gcd(C, D)

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

print(a-b-c+d)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,d = map(int, input().split())
e = 0
for l in range(a,b+1):
    if l%c == 0 or l%d == 0:
        e += 1
print(b-a-e+1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# AtCoder Beginner Contest 131
# C - Anti-Division

A,B,C,D=map(int,input().split())
if C==1 or D==1:
    print(0)
    exit()

S=set()
sC=A//C -1
eC=B//C +1

sD=A//D -1
eD=B//D +1

for i in range (sC,eC):
    tC=C*i
    if A<=tC and tC<=B:
        S.add(tC)
    if tC>B:
        break


for i in range (sD,eD):
    tD=D*i
    if A<=tD and tD<=B:
        S.add(tD)
    if tD>B:
        break

print(B-A-len(S)+1)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

l=lcm(C,D)

temp=0
for i in range(l):
    if i%C!=0:
        if i%D!=0:
            temp+=1

a=(A-1)%l
b=B%l

aa=(A-1)//l
bb=B//l

tempA=0
tempB=0

for j in range(a+1):
    if j%C!=0:
        if j%D!=0:
            tempA+=1
            
for k in range(b+1):
    if k%C!=0:
        if k%D!=0:
            tempB+=1

ans=temp*bb+tempB-(temp*aa+tempA)

print(ans)

Submission status: Time Limit Exceeded

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

cnt=0

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

print(cnt)

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

count = 0
for num in range(a, b+1):
  if num % c != 0 and num % d != 0:
    count += 1

print(count)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

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

cnt=0

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

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

lcm_cd=lcm(c,d)

for i in range(a,b+1):
  if i%lcm_cd==0:
    cnt-=1


print(b-a+1-cnt)

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def common_multiple(x, y):
    for i in range(2, min(x, y)+1):
        if x % i == 0 and y % i == 0:
            return common_multiple(x // i, y // i) * i
    return x * y

a = input().split(" ")
A, B, C, D = int(a[0]) - 1, int(a[1]), int(a[2]), int(a[3])

M = common_multiple(C, D)
B0 = B // C + B // D - B // M
A0 = A // C + A // D - A // M
print(B - A - B0 + A0)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count = 0

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
from math import *
a,b,c,d = map(int,input().split())
f =(c*d)//gcd(c,d)
r = f
rock = 2
compteur= 0
if f<=b:
  while f<=b:
    if f>=a and f<=b:
      compteur +=1
    f = r*rock
    rock += 1
div1 = ((b//c)-(a//c))
div2 = ((b//d)-(a//d))
if  a%c == 0:
  div1+=1
if a%d ==0:
  div2 +=1
roger =(div1+div2)-compteur
mm = (b-a)+1
print(mm-roger)

Submission status: Time Limit Exceeded

Solution code:
from math import *
a,b,c,d = map(int,input().split())
f =(c*d)//gcd(c,d)
r = f
rock = 2
compteur= 0
while f<=b:
  if f>=a and f<=b:
    compteur +=1
  f = r*rock
  rock += 1
div1 = ((b//c)-(a//c))
div2 = ((b//d)-(a//d))
if  a%c == 0:
  div1+=1
if a%d ==0:
  div2 +=1
roger =(div1+div2)-compteur
mm = (b-a)+1
print(mm-roger)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:

min,max,divisor1,divisor2 = list(map(int, input().split()))

count = 0
for i in range(min, max+1):
  if i % divisor1 != 0 and i % divisor2 != 0:
    count += 1

print(count)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(A,B+1):
    if (i /C).is_integer() or (i /D).is_integer():
        pass
    else:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import math
    A, B, C, D = map(int, input().split())
    S = []
    E = C
    while len(S) == 0:
        if C%E == 0 and D%E == 0:
            S.append(E)
        E -= 1
    gcd = S[0]
    lcm = C*D//gcd
    A = A-1
    print((B-B//C-B//D+B//lcm)-(A-A//C-A//D+A//lcm))
resolve()

Submission status: Time Limit Exceeded

Solution code:

[A,B,C,D] = list(map(int,input().split()))
#print(C,D)
#both
import fractions
f=fractions.gcd(C,D)
f2=C*D//f
#print(f2)

i=-1
flag=0
while True:
    i+=1
    if f2*i>=A and flag!=1:
        hajime=i
        flag=1
    elif f2*i>B:
        owari=i
        break
both=owari-hajime
#print('both', both)

#C
i=-1
flag=0
while True:
    i+=1
    if C*i>=A and flag!=1:
        hajime=i
        flag=1
    elif C*i>B:
        owari=i
        break
Ccount=owari-hajime
#print('C', Ccount)

#D
i=-1
flag=0
while True:
    i+=1
    if D*i>=A and flag!=1:
        hajime=i
        flag=1
    elif D*i>B:
        owari=i
        break
Dcount=owari-hajime
#print('D', Dcount)

print(B-A+1 -(Ccount+Dcount-both))

Submission status: Time Limit Exceeded

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

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

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

print(b - a + 1 - num)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,d = map(int,input().split())
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
if c <=0 or d <= 0:
    print("No")
ans = c * d // gcd(c,d)
i = a
j = a
while True:
    if i % c == 0:
        break
    i += 1
while True:
    if j % d == 0:
        break
    j += 1
k = min(i,j)
while True:
    if k % ans == 0:
        break
    k += 1
ii = (b-i)//c 
jj = (b-j)//d 
kk = (b-k)//ans 
print(b-a-ii-jj+kk)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
a,b,c,d = map(int,input().split())
if c <=0 or d <= 0:
    print("No")
ans = c * d // gcd(c,d)
i = a
j = a
while True:
    if i % c == 0:
        break
    i += 1
while True:
    if j % d == 0:
        break
    j += 1
k = min(i,j)
while True:
    if k % ans == 0:
        break
    k += 1
ii = (b-i)//c 
jj = (b-j)//d 
kk = (b-k)//ans 
print(b-a-ii-jj+kk)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

# check
ans = len([1 for i in range(A, B + 1) if i % C != 0 and i % D != 0])

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def division_binary_shift(a, b):

    if a < b:
        return 0
    if b == 0:
        raise ZeroDivisionError

    q = 0
    sq = 1
    ori_b = b
    while a >= b:
        b <<= 1
        if a >= b:
            sq <<= 1
        else:
            b >>= 1
            a -= b
            q += sq
            sq = 1
            b = ori_b

    return q
  
a, b, c, d = list(map(int, input().split()))
ans = 0

for num in range(a, b+1):
    c_ans = division_binary_shift(num,c)
    d_ans = division_binary_shift(num,d)
    c_flag = c_ans * c
    d_flag = d_ans * d
    
    if num - c_flag != 0 and num - d_flag != 0:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
A,B,C,D=map(int,input().split())
a={i for i in range(A,B+1)}
b=set()
c=set()
u=B//C
t=B//D
for i in range(1,u+1):
  b.add(i*C)
for j in range(1,t+1):
  c.add(j*D)
print(len(a-b-c))

Submission status: Time Limit Exceeded

Solution code:
A,B,C,D=map(int,input().split())
a={i for i in range(A,B+1)}
b=set()
c=set()
for i in range(A,B+1):
  if i%C==0:
    b.add(i)
  
for i in range(A,B+1):
  if i%D==0:
    c.add(i)
print(len(a-b-c))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
A,B,C,D=map(int,input().split())
cnt=0
for i in range(A,B+1):
    if i%C==0 or i%D==0:
        cnt+=1
    else:
        continue
print(B-A+1-cnt)

Submission status: Time Limit Exceeded

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

if __name__  == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

numbers = range(a,b+1)

t=0
for i in numbers:
    if i % c !=0 and i % d != 0:
        t += 1
print(t)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,d=map(int,input().split())
e=a
t=0
while e<=b:
  if e%c!=0 and e%d!=0:
    t+=1
  e+=1
print(t)

Submission status: Time Limit Exceeded

Solution code:
A,B,C,D = (int(x) for x in input().split())
print(len([x for x in range(A, B+1) if x % C and x % D]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(4100000)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def countDivBy(d,a,b):
    x=d
    res=0
    while (x<a):
        x+=d
    while (x<=b):
        x+=d
        res+=1
    return res
 
def gcd(c,d):
    if(d>c):
        c,d = d,c
    a,b=c,d
    r=a%b
    while (r>0):      
        a = b
        b = r 
        r = a%b
    return b

A = list(map(int, input().split()))
a, b, c, d = A
g = gcd(c,d)
lcm = int(c*d/g)
ans = b - a + 1 - countDivBy(c,a,b) - countDivBy(d,a,b) + countDivBy(lcm,a,b)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a, b, c, d = map(int, input().split())
count = 0
for i in range(a, b+1):
  if i % c == 0 or i % d == 0:
    pass
  else:
    count += 1
print(count)

Submission status: Time Limit Exceeded

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

num = b - a + 1
c_num = b // c - (a - 1) // c
d_num = b // d - (a - 1) // d

cd_max = max(c, d)
cd_min = min(c, d)
i = 1
while True:
    if (cd_max * i) % cd_min == 0:
        cd = cd_max * i
        break
    i += 1
    
cd_num = b // cd - (a - 1) // cd

#print(num, c_num, d_num, cd_num)

print(num - (c_num + d_num - cd_num))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
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 = ans + 1
    
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(a,b+1):
    if not (i % c == 0) and not (i % d == 0) :
        count = count + 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import fractions
a, b, c, d = map(int, input().split())
ans = 0
nc = 1
nc2 = 0
nd = 1
nd2 = 0 
ndc = 1
ndc2 = 0
while b >= c*nc:
  nc2 += 1
  nc += 1
while b >= d*nd:
  nd += 1
  nd2 += 1
cd = c*d//fractions.gcd(c,d)
while b >= cd*ndc:
  ndc += 1
  ndc2 += 1
nc2 -= (a-1)//c
nd2 -= (a-1)//d
ndc2 -= (a-1)//(cd)
ans = b-a+1-nc2-nd2+ndc2
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
A,B,C,D=map(int,input().split())
ans=0
m=A
while  m<=B:
  if m%C!=0 and m%D!=0:
    ans=ans+1
  m=m+1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
A,B,C,D=map(int,input().split())
ans=0
m=A
while A<=m and m<=B:
  if m%C!=0 and m%D!=0:
    ans=ans+1
  m=m+1
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

while A <= i and i <= B:
    if i%C != 0 and i%D != 0:
        cnt +=1
    i +=1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in range(A,B+1):
    X = i
    if X%C ==0 or X%D ==0:
        count += 1
print(B-A+1-count)

Submission status: Time Limit Exceeded

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

for i in range(A,B+1):
    X = i
    if X%C == 0 or X%D == 0:
        count += 1
print(B-A+1-count)

Submission status: Time Limit Exceeded

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

for i in range(B):
    x = i+1
    c = (i+1)%C
    d = (i+1)%D
    if A <= x:
        if c==0 or d==0:
            count = count
        else:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import fractions


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

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

lcm_n = lcm(c,d)

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def count(x):
    flag = False
    if x>b:
        x_count = 0
    else:
        for i in range(a,b+1):
            if i%x==0:
                x_begininng = i-a
                flag = True
                break
        else:
            x_count = 0

        if flag:
            x_count = 1 + (b-a-x_begininng)//x

    return x_count

def lcd(x,y):
    x,y = sorted([x,y])

    if x==1:
        gcd = 1
    elif x>1:
        gcd = 1
        for i in range(2,x+1):
            if x%i==0:
                if y%i==0:
                    gcd = i

    x_tmp = x//gcd
    y_tmp = y//gcd
    lcd = (gcd*x_tmp*y_tmp)

    return lcd


cd_count = count(c)+count(d)-count(lcd(c,d))
answer = (total-cd_count)

print(answer)

Submission status: Time Limit Exceeded

Solution code:
A,B,C,D=map(int,input().split())
a=[i for i in range(A,B+1) if i%C==0 or i%D==0]
print(B-A+1-len(a))

Submission status: Time Limit Exceeded

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

ans = [i for i in range(A, B+1) if i % C != 0 and i % D != 0]

print(len(ans))

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a,b,c,d = map(int, input().split())
#print(a,b,c,d)
l = []
for i in range(a,b+1):
    l.append(i)
#print(l)
x = 0
for j in l:
    if j%c!=0 and j%d!=0:
        x += 1
print(x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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