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: Time Limit Exceeded

Solution code:
def main():

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

    count = 0
    for i in list:
        if i % d != 0:
            count += 1

    print(count)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
a, b, c, d = map(int, input().split())
nums = list()
for i in range(a, b+1):
    if i%c == 0 or i%d == 0:
        continue
    nums.append(i)

print(len(nums))

Submission status: Time Limit Exceeded

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

count=0

for a in range(A,B+1):
    
    if(a%C != 0 and a%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 or i%d==0:
        cnt += 1
print(b+1-a-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())
b = b + 1
count = 0
for i in range(a,b):
  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以上b以下の数でcでもdでも割り切れない数字の個数を出力
list=[]
for i in range(a,b+1):
    if i%c!=0 and i%d!=0:
        list.append(i)
print(len(list))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(100000)


a,b,c,d=map(int,input().split())
cnt=0
ccnt=1
clist=[]
def cdo(b,c,ccnt,clist):
    if c*ccnt>b:
        return clist
    if a<=c*ccnt:
        clist+=[c*ccnt]
    ccnt+=1
    return cdo(b,c,ccnt,clist)
dcnt=1
dlist=[]
def ddo(b,d,dcnt,dlist):
    if d*dcnt>b:
        return dlist
    if a<=d*dcnt:
        dlist+=[d*dcnt]
    dcnt+=1
    return ddo(b,d,dcnt,dlist)

print(b-a-len(set(cdo(b,c,ccnt,clist)+ddo(b,d,dcnt,dlist)))+1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
inputs = input().split()
a = int(inputs[0])
b = int(inputs[1])
c = int(inputs[2])
d = int(inputs[3])

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:
# -*- coding: utf-8 -*-

List = [int(x) for x in input().split()]
A = List[0]
B = List[1]
C = List[2]
D = List[3]

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

countsum = 0
countC = 0
countD = 0
countC_D = 0
for i in range(A,B+1,1):
  countsum += 1
  if i % C == 0:
    countC += 1
  if i % D == 0:
    countD += 1
  if i % C == 0 and i % D == 0:
    countC_D += 1

print(countsum-countC-countD+countC_D)

Submission status: Time Limit Exceeded

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

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

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())
li = [i for i in range(a, b+1)]
cf = [True if i%c != 0 else False for i in li]
df = [True if i%d != 0 else False for i in li]
n = 0
for i in range(len(cf)):
    if cf[i] and df[i]:
        n+=1
print(n)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,d = (int(i) for i in 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=list(map(int,input().split()))
print(len([i for i in range(A,B+1) if i%C!=0 and i%D!=0]))

Submission status: Time Limit Exceeded

Solution code:
s=list(map(int,input().split()))
i=0
a=0
list=[]
for i in range(s[0],s[1]+1):
  if i%s[2]!=0 and i%s[3]!=0:
    a=a+1
print(a)

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:
    continue
  else:
    if i%d == 0:
      continue
    else:
      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())
f = [i for i in range(a,b+1) if not ((i%c==0)or(i%d==0))]
print(len(f))

Submission status: Time Limit Exceeded

Solution code:
A, B, C, D = map(int, input().split())
count = 0
#AからBをiに代入
for i in range(A, B+1):
    if i % C != 0 and i % D != 0:
        count = count + 1
    else:
        pass   #何もしない

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, 1):
    if i % C != 0 and i % D != 0:
        ans += 1
    else:
        pass

print(ans)

Submission status: Time Limit Exceeded

Solution code:
not_div = 0
n = list(map(int, input().split()))
for i in range(n[0], n[1]+1):
  if (i % n[2] !=0 and i % n[3] !=0):
    not_div +=1
  else:
    pass
print(not_div)

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 = input().split()
#nums = list(range(int(A), int(B)+1))
#tmp = [x for x in nums if not x%int(C) == 0 and not x%int(D) == 0]
#print(len(tmp))
count =0
for i in range(int(A), int(B)+1):
  if not i%int(C) == 0 and not i%int(D) == 0:
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
a, b, c, d = list(map(int, input().split()))
def divNumCount(start, end, div):
    count = 0
    num = 0
    i = start
    while i <= end:
        if i % div == 0:
            i += div - 1
            count += 1
        i += 1
    return count
def euqlid(a,b):
    if a < b:
        temp = a
        a = b
        b = temp
    while(a % b != 0):
        temp = a % b
        a = b
        b = temp
    return b

C = 0
D = 0
CandD = 0
C = divNumCount(a, b, c)
D = divNumCount(a, b, d)
CandD = divNumCount(a, b, c * d / euqlid(c,d))
print(b - a + 1 - (C + D - CandD))

Submission status: Time Limit Exceeded

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

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):
    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 not (i % c == 0 or 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())
a=A
num=B-A+1
while a<=B:
    if a%C==0:
        num=num-1
    elif a%D==0:
        num=num-1
    a=a+1
print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ll = [((i % c != 0) and (i % d != 0)) for i in range(a, b+1)]
print(ll.count(True))

Submission status: Time Limit Exceeded

Solution code:
A,B,C,D = (int(x) for x in input().split())
n = A
count = 0
while n <= B:
    if n%C != 0:
        if n%D != 0:
            count += 1
    n += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
A,B,C,D = (int(x) for x in input().split())
n = A
count = 0
while n <= B:
    if n%C != 0 and n%D != 0:
        count += 1
    n += 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 = input().split()
a,b,c,d = int(a),int(b),int(c),int(d)
ad = []
for num in range(a,b+1):
    if num%c!=0:
        if num%d!=0:
            ad.append(num)

print(len(ad))

Submission status: Time Limit Exceeded

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

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())
l=[]
for n in range(A,B+1):
  if (n%C)==0 or (n%D)==0:
    l.append(n)
print(B-A+1-len(l))

Submission status: Time Limit Exceeded

Solution code:
A,B,C,D=map(int,input().split())
l=[]
for n in range(A,B+1):
  if (n%C)!=0 and (n%D)!=0:
    l.append(n)
print(len(l))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

c_list = [C*i for i in range(B//C+1)]

d_list = [D*i for i in range(B//D+1)]

koho = [i for i in range(A,B+1)]

for c in c_list:
    try:
        koho.remove(c)
    except ValueError:
        pass

for d in d_list:
    try:
        koho.remove(d)
    except ValueError:
        pass
# print(koho)

print(len(koho))

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:
import sys

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

# A: 5 B: 10 C: 3 D: 7
ans = 0
for i in range(b-a+1):
    n = i + a
    if n % c != 0 and n % d != 0:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
A,B,C,D=[int(x) for x in input().split()]
i,t=A,0
while i<=B:
    if i%C==0 or i%D==0:
        i=i+1
    else:
        t=t+1
        i=i+1
print(t)

Submission status: Time Limit Exceeded

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

a_b = [i for i in range(a,b+1) if i % c == 0 or i % d == 0]

ans = (b + 1 - a) - len(a_b)
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:
            count += 1
        elif i % d == 0:
            count += 1

ans = (b+1 - a - count)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count = 0
def y(i):
    global count
    count += bool(i % c and i % d)
threads = [threading.Thread(target=y, args=[i]) for i in range(a, b + 1)]
[t.start() for t in threads]
[t.join() for t in threads]
print(count)

Submission status: Time Limit Exceeded

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


def y(i):
    return bool(i % c and i % d)

ans = map(y, range(a, b + 1))
print(sum(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())
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())
lis=[]
ans=0
for i in range(B-A+1):
    j =A+i
    if    j%C !=0 and j%D!=0:
        ans +=1
        
        
    

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
a, b, c, d = [int(i) for i in input().split()]
cnt = 0
for i in range(b+1)[a:]:
    cnt += (((i % c) != 0) and ((i % d) != 0))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
input=input().split()

count=0
A=int(input[0])
B=int(input[1])
C=int(input[2])
D=int(input[3])
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())
lis=[]
ans=0
for i in range(B-A+1):
    j =A+i
    if    j%C !=0 and j%D!=0:
        
        
        lis.append(j)
    
ans=len(lis)
print(ans)

Submission status: Time Limit Exceeded

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

tmp = set()

i = a
j = None if a > c else c
k = None if a > d else d
while(j is None or k is None):
    if j is None and i % c == 0:
        j = i
    if k is None and i % d == 0:
        k = i
    i += 1

while(j <= b):
    tmp.add(j)
    j += c

while(k <= b):
    tmp.add(k)
    k += d

print((b - a + 1) - len(tmp))

Submission status: Time Limit Exceeded

Solution code:
import fractions
a,b,c,d = map(int,input().split())
count_c = 0
count_d = 0
count_cd = 0
count = 0
j = 1
g = c*d//fractions.gcd(c,d)
while(1):
    if c*j <= b and c*j>=a:
        count_c += 1
    if d*j <=b and d*j >= a:
        count_c += 1
    if g*j <=b and g*j >= a:
        count_cd += 1
    if c*j > b and d*j > b and g*j > b:
        break
    j += 1
s = count_c+count_d-count_cd
print(b-a +1-s)

Submission status: Time Limit Exceeded

Solution code:
abcd = input().split(" ")
count = 0

for mizuki in range(int(abcd[0]), int(abcd[1]) + 1):
  if mizuki % int(abcd[2]) == 0:
    count += 1
  elif mizuki % int(abcd[3]) == 0:
    count += 1
    
print(int(abcd[1]) - int(abcd[0]) + 1 - count)

Submission status: Time Limit Exceeded

Solution code:
# スペース区切りの整数の入力（別変数に格納）
A,B,C,D = map(int, input().split())
# A,B,C,D = 314159265358979323, 846264338327950288, 419716939, 937510582
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):
#     print(i)

    if c <= i:
        if i % c == 0:
            continue
            
    if d <= i:
        if i % d == 0:
            continue
    
#     print(i)
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
A,B,C,D = map(int, input().split())
cmlist,dmlist=[],[]
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
while(A <= B):
  if A%C != 0 and A%D != 0:
    cnt += 1
  A += 1
  
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def saidaikouyaku(a, b):
    if b > a:
        a, b = b, a

    while b != 0:
        a, b=b,a%b
    return a

A, B, C, D = map(int, input().split())
hani = B - A + 1
count = 0
count2 = 0
count3 = 0
saisyoukoubai = int(C * D / saidaikouyaku(C, D))
for i in range(A, B + 1):
    if i % C == 0:
        count += 1
    if i %  D == 0:
        count2 += 1
    if i % saisyoukoubai == 0:
        count3 += 1

print(hani - count - count2 + count3)

Submission status: Time Limit Exceeded

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

lcm=C*D
#print(A, B-A+1)
ans = []

for i in range(A, B+1):
	#print(i)
	if i%C != 0 and i%D != 0:
		#print('warikirenai')
		ans.append(i)

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import math
a = [int(i) for i in input().split()]
num = {i for i in range(a[0],a[1]+1)}

s_c = math.floor(a[0]/a[2])
e_c = math.floor(a[1]/a[2])
s_d = math.floor(a[0]/a[3])
e_d = math.floor(a[1]/a[3])
c_set = {i*a[2] for i in range(s_c,e_c+1)}
d_set = {i*a[3] for i in range(s_d,e_d+1)}

union = c_set | d_set
answer = num-union
print(len(answer))

Submission status: Time Limit Exceeded

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

base = [i for i in range(a, b+1) if not i%c==0 and not i%d==0]

print(len(base))

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 or num % D == 0:
        continue
    else:
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

num=all-count
print(num)

Submission status: Time Limit Exceeded

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

co=0
for _ in range(b-a+1):
  if a%c!=0 and a%d!=0:
    co+=1
  a+=1
print(co)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

print(indivisible)

Submission status: Time Limit Exceeded

Solution code:
a, b, c, d = map(int, input().split())
cf = True
df = True
cn = c
dn = c
cs = set()
ds = set()
while(cf == True):
  if cn >= a and cn <= b:
    cs.add(cn)
  cn += c
  if cn > b:
    cf = False
while(df == True):
  if dn >= a and dn <= b:
    ds.add(dn)
  dn += d
  if dn > b:
    df = False
us = cs.union(ds)
s = b-a+1-len(us)
print(s)

Submission status: Time Limit Exceeded

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

def lcm(x,y):
  return x*y//gcd(x,y)
a, b, c, d = list(map(int, input().split()))

num_mul_c = 0
num_mul_d = 0
num_mul_cd = 0

n=1
while True:
    nc = n*c
    if nc>b:
        break
    if (a<=nc)and(nc<=b):
        num_mul_c += 1
    n += 1
n=1
while True:
    nd = n*d
    if nd>b:
        break
    if (a<=nd)and(nd<=b):
        num_mul_d += 1
    n += 1
n=1
cd = int((c*d)//gcd(c, d))
while True:
    ncd = cd*n
    if ncd>b:
        break
    if (a<=ncd)and(ncd<=b):
        num_mul_cd += 1
    n += 1
print(b-a+1 - num_mul_c - num_mul_d + num_mul_cd)

Submission status: Time Limit Exceeded

Solution code:
lis=list(map(int,input().split()))
A=lis[0]
B=lis[1]
C=lis[2]
D=lis[3]
sum=B-A+1
gcd=1
for x in range(C):
  if D%(1+x)==0 and C%(1+x)==0:
    gcd=1+x
times=C*D//gcd
restac=A%C
restbc=B%C
restad=A%D
restbd=B%D
restat=A%times
restbt=B%times
x=int((B-restbc)//C)-int((A-restac)//C)
y=int((B-restbd)//D)-int((A-restad)//D)
z=int((B-restbt)//times)-int((A-restat)//times)
if restac==0:
  x+=1
if restad==0:
  y+=1
if(restat==0):
  z+=1
print(sum-x-y+z)

Submission status: Time Limit Exceeded

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

cnt = 0    
print(sum([1 for x in range(a, b+1) if x % c != 0 and x % d != 0]))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


class C:
	def __init__(self,A,B,C,D):
		self.A = int(A)
		self.B = int(B)
		self.C = int(C)
		self.D = int(D)
		self.ans_list = list()
	def main(self):
		for i in range(self.A,self.B+1):
			if i % self.C != 0:
				if  i % self.D != 0:
					self.ans_list.append(i)

		print(len(self.ans_list))


Inp = stdin.readline()
Inp = Inp.replace('\n','')
Inp = Inp.split()

do = C(Inp[0],Inp[1],Inp[2],Inp[3])

do.main()

Submission status: Time Limit Exceeded

Solution code:
a,b,c,d = (int(i) for i in input().split())
count = 0
cs = 1
ds = 1
while cs * c <= b:
    if(cs * c < a):
        cs = cs + 1
        continue
    count = count + 1
    cs = cs + 1
while ds * d <= b:
    if(ds * d < a):
        ds = ds + 1
        continue
    if (ds * d) % c != 0:
        count = count + 1
    ds = ds + 1
print(b-a + 1 - 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)

l = [x for x in range(a, b+1)]
#print(l)

l2 = []
for x in l:
  if (x % c != 0 and x % d !=0):
    l2.append(x)

print(len(l2))

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:
        count += 1
print(B-A+1-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:
while True:
  a=1

Submission status: Time Limit Exceeded

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

num=all-count
print(num)

Submission status: Time Limit Exceeded

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

X = [x for x in range(a, b+1) if x%c!=0]
Y = [x for x in X if x%d!=0]

print(len(Y))

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:
        if i % D != 0:
            cnt +=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
A,B,C,D=map(int,input().split())
# L=[0]*(B-A)
L=set()
t1=B
while True:
	if t1%C==0:
		while t1>=A:
			L.add(t1)
			t1-=C
		break
	else:
		t1-=1

t2=B
while True:
	if t2%D==0:
		while t2>=A:
			L.add(t2)
			t2-=D
		break
	else:
		t2-=1
print(B-A+1-len(L))

Submission status: Time Limit Exceeded

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

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

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

c_first = 0
c_last = 0
d_first = 0
d_last = 0
cd_first = 0
cd_last = 0

for i in range(A,B+1,1):
  if c_first == 0 and i % C == 0:
    c_first = i // C
  if d_first == 0 and i % D == 0:
    d_first = i // D
  if cd_first == 0 and i % CD == 0:
    cd_first = i // CD  
  if c_first != 0 and d_first != 0 and cd_first != 0:
    break

for i in range(B,A-1,-1):
  if c_last == 0 and i % C == 0:
    c_last = i // C
  if d_last == 0 and i % D == 0:
    d_last = i // D
  if cd_last == 0 and i % CD == 0:
    cd_last = i // CD
  if c_last != 0 and d_last != 0 and cd_last != 0:
    break

c_count = 0
d_count = 0
cd_count = 0
if c_first != 0:
  c_count = c_last - c_first + 1
if d_first != 0:
  d_count = d_last - d_first + 1
if cd_first != 0:
  cd_count = cd_last - cd_first + 1
    
#print(c_first, c_last, d_first, d_last, cd_first, cd_last)
#print(c_count, d_count, cd_count)
print(B - A + 1 - (c_count + d_count - cd_count))

Submission status: Time Limit Exceeded

Solution code:
def main():
    a, b, c, d = map(int, input().split())
    l = []
    for i in range(a,b+1):
        if i%c == 0 or i%d == 0:
            continue
        else:
            l.append(i)

    print(len(l))

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

# ans = 0
# for x in range(a, b+1):
#     if x % c !=0:
#         if x % d !=0:
#             ans += 1
#     else:
#         pass
X = [x for x in range(a, b+1) if (x%c!=0 and x%d!=0)]
# for x in range(a, b+1):
#     if x % c !=0:
#         if x % d !=0:
#             ans += 1
#     else:
#         pass

# print(X)
print(len(X))

Submission status: Time Limit Exceeded

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

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
s = input().split()
count=0
for i in range(int(s[0]),int(s[1])+1):
    if i%int(s[2]) and i%int(s[3])!=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())
N = B - A +1
count = 0
for i in range(N):
  M = i + A
  if M % C != 0:
    if M % D != 0:
      count +=1
    else:
      continue
  else:
    continue
print(count)

Submission status: Time Limit Exceeded

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

cnt = 0

for i in range(b-a+1):
    tmp=a+i
    if tmp%c!=0:
        if tmp%d!=0:
            cnt += 1
    
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        r = x % y
        x = y
        y = r
    return x


def main():
    A, B, C, D = map(int, input().split())
    tmp = 0
    R = int(C * D / gcd(C, D))
    flag = True
    i = 1
    while flag:
        if C * i < A:
            i += 1
        elif C * i <= B:
            i += 1
            tmp += 1
        else:
            break

    flag = True
    i = 1
    while flag:
        if D * i < A:
            i += 1
        elif D * i <= B:
            i += 1
            tmp += 1
        else:
            break

    flag = True
    i = 1
    while flag:
        if R * i < A:
            i += 1
        elif R * i <= B:
            i += 1
            tmp -= 1
        else:
            break

    print(B-A+1-tmp)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
a, b, c, d = map(int, input().split())
x = b - a + 1
# cnt_a = a
# cnt_b = b
cnt = 0



while a <= b:
    # print("aの値", a)
    
    if a % c == 0 or a % d == 0:
        # print(a)
        
        cnt += 1
    # print(a)
    a += 1

# print(x, cnt)
print(x - cnt)

Submission status: Time Limit Exceeded

Solution code:
A, B, C, D=map(int, input().split())
N=A
Count=0
while N<B+1:
    if N%C!=0 and N%D!=0:
        Count+=1
    N+=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 != 2):
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
A, B, C, D = map(int, input().split())
E = []
S = 0
for i in range(A, B+1):
    # if E[i-A] == 1:
    #     continue
    if i in E:
        E.remove(i)
        continue
    else:
        if i%C == 0:
            t = (B - i) // C
            for j in range(2, t+1):
                # E[i-A+j*C] = 1
                E.append(i+j*C)
        elif i%D == 0:
            t = (B - i) // D
            for j in range(2, t+1):
                # E[i-A+j*D] = 1
                E.append(i+j*D)
        else:
            S += 1
print(S)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def C():
    import fractions
    
    def counter (target):
        if  target > B:
            return 0
        for i in range(A, B + 1):
            if i % target == 0:
                leg = B - i
                count = (leg // target) + 1
                return count            
        return 0
    A, B, C, D = map(int, input().split())
    lcm = (C * D) // fractions.gcd(C, D)
    print(B - A + 1 - (counter(C) + counter(D) - counter(lcm)))
C()

Submission status: Time Limit Exceeded

Solution code:
a,b,c,d = map(int,input().split())
count = 0
for _ in range(a, b+1):
    if _%c != 0 and _%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 or i % d == 0:
    continue
  cnt +=1

print(cnt)

Submission status: Time Limit Exceeded

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

an = 0
for x in range(a,b+1):
    if x % c != 0:
        if x % d != 0:
            an += 1
            

print(an)

Submission status: Time Limit Exceeded

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

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

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

result = 0
while(True):
  if A%C == 0 or A%D == 0:
    A += 1
  else:
    break

result += (B-A+1) - (B//C - A//C) - (B//D - A//D)
l = lcm(C, D)
result += (B//l - A//l)

print("{}".format(result))

Submission status: Time Limit Exceeded

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

print(len(cdm))