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().split())
lcm = c * d / math.gcd(c , d) 

if a % c == 0:
    c_start = int(a/c)
else:
    c_start = int(a/c)+1

if a % d == 0:
    d_start = int(a/d)
else:
    d_start = int(a/d)+1

if a % lcm == 0:
        lcm_start = int(a/lcm)
else:
        lcm_start = int(a/lcm)+1

c_end = int(b/c)
d_end = int(b/d)
lcm_end = int(b/lcm)

c_num = c_end - c_start + 1
d_num = d_end - d_start + 1
lcm_num=lcm_end - lcm_start + 1

print(b - a + 1 - c_num - d_num + lcm_num)

Submission status: Runtime Error

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

a = math.ceil((B / C) - (A / C))
b = math.ceil((B / D) - (A / D))
c = sympy.lcm(C, D)
while c < A:
    c += c
tmp = 0
while c <= B:
    c += c
    tmp += 1
print(B - A + 1 - (a + b - tmp))

Submission status: Runtime Error

Solution code:
import math

x = input()
x = str(x).split(" ")
f = 0

a = int(x[0])
b = int(x[1])
c = int(x[2])
d = int(x[3])

n = b-a+1

if c-a%c < n%c :
  f+=1

if d-a%d < n%d :
  f+=1

if c*d-a%(c*d) < n%(math.gcd(c, d)) :
  f-=1
  
print( n - int(n/d) - int(n/c) + int(n/(math.gcd(c, d)) - f))

Submission status: Runtime Error

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

if c == 1 or d == 1:
    print(0)
else:
    an1 = math.floor(b/c)
    an2 = math.floor((a-1)/c)
    an3 = math.floor(b/d)
    an4 = math.floor((a-1)/d) 
    gcd = round(c * d / gcd(c, d))
    an5 = math.floor(b/gcd)
    an6 = math.floor((a-1)/gcd)
    an = an1-an2 + an3-an4 -(an5-an6)
    print((b-a+1)-an)

Submission status: Runtime Error

Solution code:
import math

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

a = int(a)
b = int(b)
c = int(c)
d = int(d)

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

counter = 0

counter = counter + ((b // c) + (b // d) - (b // hoge))
counter = counter - (((a - 1) // c) + ((a - 1) // d) - ((a - 1) // hoge))

print(b - a + 1 - counter)

Submission status: Runtime Error

Solution code:
def abc():
    from math import ceil
    _a, _b, c, d = map(int, input().split())

    a = min(_a, _b)
    b = max(_a, _b)

    cnt_all = b - a + 1

    l = ceil(a / c)
    r = b // c
    cnt_c = r - l + 1

    l = ceil(a / d)
    r = b // d
    cnt_d = r - l + 1

    cd = lcm(c, d)
    l = ceil(a / cd)
    r = b // cd
    cnt_cd = r - l + 1

    print(cnt_all - (cnt_c + cnt_d - cnt_cd))


abc()

Submission status: Runtime Error

Solution code:
import math

a,b,c,d = map(int, input().split())
cnt = 0
ansb1 = b // c
ansb2 = b // d
ansb12 = b // (c*d//(math.gcd(c,d)))
bb = (ansb1 + ansb2) - ansb12

ansa1 = (a-1) // c
ansa2 = (a-1) // d
ansa12 = (a-1) // (c*d//(math.gcd(c,d)))
aa = (ansa1 + ansa2) - ansa12
print((b-a+1)-(bb-aa))

Submission status: Runtime Error

Solution code:
import sympy
A,B,C,D=map(int,input().split())
X=0
L=0
M=0
N=0
E=C*D/sympy.gcd(C,D)
if A%C==0 or B%C==0:
    L=(B-A)//C+1
else:
    L=(B-A)//C

if A%D==0 or B%D==0:
    M=(B-A)//D+1
else:
    M=(B-A)//D
if B-A>=E:
    if A%E==0 or B%E==0:
        N=(B-A)//E+1
    else:
        N=(B-A)//E
else:
    if A%E==0 or B%E==0:
        N=(B-A)//E+2
    else:
        N=(B-A)//E+1
X=B-A+1-L-M+N
print(int(X))

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())
CD=lcm(C, D)

def xc(x,C=C,D=D,CD=CD):
    return(x//C+x//D-x//(CD))

print(B-A+1-xc(B+1)+xc(A))

Submission status: Runtime Error

Solution code:
import math

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

AtoB = (B - (A - 1))

divisible_C = (B // C) - ((A - 1) // C)
divisible_D = (B // D) - ((A - 1) // D)

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

divisible_CD = (B // minLcm) - ((A - 1) // minLcm)

divisible_CandD = (divisible_C + divisible_D) - divisible_CD

answer = AtoB - divisible_CandD

print(answer)

Submission status: Runtime Error

Solution code:
import math

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 = (c*d)//math.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: 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())
cd = lcm(c, d)
num = b - a + 1

if a <= cd <= b:
    cd_count = (b // cd) - (a // cd)
else:
    cd_count = 0

if a % c == 0:
    c_count = (b // c) - (a // c) + 1
else:
    c_count = (b // c) - (a // c)
if a % d == 0:
    d_count = (b // d) - (a // d) + 1
else:
    d_count = (b // d) - (a // d)

ans = num - c_count - d_count + cd_count

print(ans)

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<stdio.h>
//#include<array>

#define rep(i,n) for(int i=0;i<(n);i++)
#define LL long long int


using namespace std;

int main(void){
    LL a,b,c,d;
    cin >> a>>b>>c>>d;

    LL ans=0;
    /* 
    for(int i =a; i<b; i++){

        if(i%c!=0 && i%d!=0){
            ans++;
        }

    }*/

    LL C =b/c-a/c;
      LL D= b/d-a/d;
    /* vector<LL> lista(C);
    int h=0;
    for(LL i =a/c,h=0;i<b/c;h++,i++){
        lista[h]=i*a;
        cout<<lista[h]<< " " << h<< " " << i<< " " << i*a<<endl;
    }
    LL x;
  
    LL j=0;
    LL EX=0;
   for(LL i =a/d;i<b/d;i++){
        x=i*b;
         while(x>lista[j] )j++;
        cout<<x<< " " << lista[j]<< " " << h<< " " << j<<endl;
        if(lista[j]==x)EX++;
        if( h>j)break;

   }*/

    cout <<b-a+1-(C+D)<<endl;
    return 0;
}

Submission status: Runtime Error

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

import math

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


n1 = math.ceil(A/C)
n2 = math.ceil(A/D)
n3 = math.ceil(A/E)


m1 = math.floor(B/C)
m2 = math.floor(B/D)
m3 = math.floor(B/E)

cnt_c = m1-n1+1
cnt_d = m2-n2+1
cnt_cd = m3-n3+1

print(interval-(cnt_c+cnt_d-cnt_cd))

Submission status: Runtime Error

Solution code:
import math

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

ans = B - A + 1

# A以上B以下の数でXの倍数の個数
def countX(X) :
    if X > B :
        return 0
    minX = math.ceil(A / X)
    maxX = math.floor(B / X)

    return maxX - minX + 1

# 最小公倍数
Z = int(C * D / math.gcd(C,D))

ans += -countX(C) - countX(D) + countX(Z)

print(ans)

Submission status: Runtime Error

Solution code:
import collections

N = input().strip()
N = int(N)
dic = collections.defaultdict(lambda: 0)

for i in range(N):
    x,y = input().strip().split(" ")
    x = int(x)
    y = int(y)

    dic[y] += x

prev_time = 0
result = "Yes"

for k,v in dic.items():
    if v > k:
        result = "No"
        break
    prev_time += v

print(result)

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

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

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

num_c = num(a, b, c)
num_d = num(a, b, d)
num_lcm = num(a, b, lcm)
n = num_c + num_d - num_lcm
result = b - a + 1 - n

print(result)

Submission status: Runtime Error

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


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

def count(st, n):
    ans = (b - st + 1) // n
    return ans


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


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


sum = 0
cc = 0
cflag = True
dflag = True
cdflag = True
for i in range(a, b + 1):
    if i % c == 0 and cflag:
        sum += count(i, c)
        cc += 1
        cflag = False
    if i % d == 0 and dflag:
        if dflag:
            sum += count(i, d)
            cc += 1
            dflag = False
        if i % c == 0 and cdflag:
            l = lcm(c, d)
            sum -= count(i, l)
            cc += 1
            cdflag = False
    if cc == 3:
        break
print(b - a + 1 - sum)

Submission status: Runtime Error

Solution code:
# C - Anti-Division
import math


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


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

AtoB = (B - (A - 1))

divisible_C = (B // C) - ((A - 1) // C)
divisible_D = (B // D) - ((A - 1) // D)

minLcm = lcm(C, D)
divisible_CD = (B // minLcm) - ((A - 1) // minLcm)

divisible_CandD = (divisible_C + divisible_D) - divisible_CD

answer = AtoB - divisible_CandD

print(answer)

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
gcdc=[]
gcdd=[]
for i in range(1,int(c**(1/2))+1):
  if c%i==0:
    gcdc.append(i)
    if i!=c//i:
      gcdc.append(c//i)
for i in range(1,int(d**(1/2))+1):
  if d%i==0:
    gcdd.append(i)
    if i!=d//i:
      gcdd.append(d//i)
E=[]
for i in range(len(gcdc)):
  if gcdc[i] in gcdd:
    E.append(gcdc[i])
e=1
for i in range(len(E)):
  e*=E[i]
f=c*d//e
g=0
h=0
i=0
if a%c==0:
  g=b//c-a//c+1
else:
  g=b//c-a//c
if a%d==0:
  h=b//d-a//d+1
else:
  h=b//d-a//d
if a%f==0:
  i=b//f-a//f+1
else:
  i=b//f-a//f
print(b-a+1-g-h+i)

Submission status: Runtime Error

Solution code:
import math

A, B, C, D = map(int,input().split())
CD = C * D / math.gcd(C, D)
numC = int(B/C) - int((A-1)/C)
numD = int(B/D) - int((A-1)/D)
numCD = int(B/(CD)) - int((A-1)/(CD))
print(B - A + 1 - (numC + numD - numCD))

Submission status: Runtime Error

Solution code:
import math

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

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

a = int(a)
b = int(b)
c = int(c)
d = int(d)

saisyo_kobaisu = lcm(c, d)

counter = 0

counter = counter + ((b // c) + (b // d) - (b // saisyo_kobaisu))
counter = counter - (((a - 1) // c) + ((a - 1) // d) - ((a - 1) // saisyo_kobaisu))

print(b - a + 1 - counter)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import math

A, B, C, D = map(int, input().split())
subst = abs(A - B)
num1 = subst // C + 1
num2 = subst // D + 1
num3 = subst // (C * D // math.gcd(C, D)) + 1

print(subst - num1 - num2 + num3 + 1)

Submission status: Runtime Error

Solution code:
import numpy as np

import math

a = input().split(" ")

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

min = min(C,D)
max = max(C,D)
gcd = int((min*max)/math.gcd(min,max))
c_num = 0
if A%min == 0:
     c_num = int(B/min) - int(A/min) + 1
else:
    c_num = int(B/min) - int(A/min)

d_num = 0
if A%max == 0:
     d_num = int(B/max) - int(A/max) + 1
else:
    d_num = int(B/max) - int(A/max)


gcd_num = 0
if A%gcd == 0:
     gcd_num = int(B/gcd) - int(A/gcd) + 1
else:
    gcd_num = int(B/gcd) - int(A/gcd)


print(B-A+1-c_num-d_num+gcd_num)

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

AtoB = (B - (A - 1))

divisible_C = (B // C) - ((A - 1) // C)
divisible_D = (B // D) - ((A - 1) // D)

minLcm = lcm(C, D)
divisible_CD = (B // minLcm) - ((A - 1) // minLcm)

divisible_CandD = (divisible_C + divisible_D) - divisible_CD

answer = AtoB - divisible_CandD

print(answer)

Submission status: Runtime Error

Solution code:
from math import gcd
a,b,c,d=map(int,input().split( ))
r1=b-b%c
if a%c!=0:
	l1=a-a%c+c
else:
	l1=a
r2=b-b%d
if a%d!=0:
	l2=a-a%d+d
else:
	l2=a
lcm=(c*d)//gcd(c,d)
r3=b-b%lcm
if a%lcm!=0:
	l3=a-a%lcm+lcm
else:
	l3=a
nc=(r1-l1+c)//c
nd=(r2-l2+d)//d
nlcm=(r3-l3+lcm)//lcm
divi=nc+nd-nlcm
out=b-a+1
print(out-divi)

Submission status: Runtime Error

Solution code:
def gue(n, m):
  return n - n//m
import math
a, b, c, d = map(int, input().split())
c_ = gue(b, c)-gue(a-1,c)
d_ = gue(b, d)-gue(a-1,d)
c_d_ = gue(b, c*d//math.gcd(c,d)) - gue(a-1,c*d//math.gcd(c,d))
print(c_+d_-c_d_)

Submission status: Runtime Error

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

X = (C * D) // math.gcd(C, D)
Y = (C + D) // math.gcd(C, D) - 1

#print(X,Y)

#count = (B - A) // X * Y 
#print(count)


N = A % X 
N_S = N-1
UA = Y - (N_S // C + N_S // D)

#print(UA)
M = B % X
UB = M // C + M // D
if M == 0:
    UB = 0
#print(UB)


SA =  A + ( X - N )
SB =  B - M 
#print(SA,SB)
count = (SB - SA) // X * Y 

#print(count)
add = count + UA + UB
    
Z = B - A - add + 1
print(Z)

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())
sa = b-a+1
a1 = int((sa + a%c)/c)
a2 = int((sa + a%d)/d)
a3 = int((sa + a%(lcm(c, d)))/(lcm(c, d)))
print(sa-a1-a2+a3)
#print(a1)
#print(a2)
#print(a3)
#print(lcm(c, d))
#31
# 12 18 24 30 36
# 16 24 32 40
#3+2-1 = 4
#9-4+1 - 4

Submission status: Runtime Error

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

def wareruzu(x):
    if b < x:
        return 0
    start_a = a if a % x == 0 else a - (a % x) + x
    end_b = b - (b % x)
    m = end_b - start_a
    return int(m / x) + 1

all_n = b - a + 1
print(all_n - wareruzu(c) - wareruzu(d) + wareruzu((c*d) / math.gcd(c,d)))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

X = (C * D) // math.gcd(C, D)
Y = (C + D) // math.gcd(C, D) - 1

print(X,Y)

#count = (B - A) // X * Y 
#print(count)


N = A % X 
N_S = N-1
UA = Y - (N_S // C + N_S // D)

print(UA)
M = B % X
UB = M // C + M // D
if M == 0:
    UB = 0
print(UB)


SA =  A + ( X - N )
SB =  B - M 
print(SA,SB)
count = (SB - SA) // X * Y 

print(count)
add = count + UA + UB
    
Z = B - A - add + 1
print(Z)

Submission status: Runtime Error

Solution code:
import math

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

bandc = b // c 
bandd = b // d
bandcd = b // ((c*d) // math.gcd(c,d))

aandc = a // c 
aandd = a // d
aandcd = a // ((c*d) // math.gcd(c,d))

totalb = b - bandc - bandd + bandcd
totala = a - aandc - aandd + aandcd
#print(totalb)
#print(totala)
print(totalb-totala)

Submission status: Runtime Error

Solution code:
import math

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

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

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

num_c = num(a, b, c)
num_d = num(a, b, d)
num_lcm = num(a, b, lcm)
n = num_c + num_d - num_lcm
result = b - a + 1 - n

print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
import math

A, B, C, D = map(int, input().split())
subst = abs(A - B)
num1 , num2, num3 = (subst // C + 1), (subst // D + 1), (subst // (C * D // math.gcd(C, D))) + 1

print(subst - num1 - num2 + num3 + 1)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect
import heapq

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

x = list(map(int, input().split()))

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

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


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

    
def main():
    res = 0
    tmp = 0
    if A%C == 0:
        tmp+=1    
    NC = B//C - A//C + tmp
    
    tmp = 0
    if A%D == 0:
        tmp+=1


    ND = B//D - A//D + tmp
    
    tmp=0
    lcm_CD =lcm(C, D)

    if A%lcm_CD == 0:
        tmp+=1
    lcm_CD =lcm(C, D) +tmp
    
    NCD= B//lcm_CD - A//lcm_CD 
    res = B-A+1 -(NC+ND-NCD)
    #print(NC, ND, NCD)        
        
        
        
    
    print(res)
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys, math

def CountDivisibleNumber(divisor, min, max):
    i = 0
    count = 0
    residue = min % divisor
    if residue == 0:
        i = min
    else:
        if min < divisor:
            i = divisor
        else:
            i = min + (divisor - residue)
            #print(residue)
            #print(i)

    while i <= max:
        count += 1
        i += divisor
        #print(i)
    
    return count

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

S = input().split()

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

count_U = B - A + 1

count_C  = CountDivisibleNumber(C, A, B)
#print(count_C)
count_D  = CountDivisibleNumber(D, A, B)
#print(count_D)
count_CD = CountDivisibleNumber(lcm(C, D), A, B)
#print(count_CD)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

cal_list = np.arange(A,B+1)
cal_list_C = cal_list % C
cal_list_D = cal_list % D

not0_C = (cal_list_C!=0)
not0_D = (cal_list_D!=0)

not0_both = np.where((not0_C==not0_D) & (cal_list_C!=0) & (cal_list_D!=0))[0]

print(len(not0_both))

Submission status: Runtime Error

Solution code:
import numpy as np
import math

a = input().split(" ")

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

min = min(C,D)
max = max(C,D)
gcd = (min*max)/math.gcd(min,max)

c_num = 0
if A%min == 0:
     c_num = int(B/min) - int(A/min) + 1
else:
    c_num = int(B/min) - int(A/min)

d_num = 0
if A%max == 0:
     d_num = int(B/max) - int(A/max) + 1
else:
    d_num = int(B/max) - int(A/max)


gcd_num = 0
if A%gcd == 0:
     gcd_num = int(B/gcd) - int(A/gcd) + 1
else:
    gcd_num = int(B/gcd) - int(A/gcd)


print(B-A+1-c_num-d_num+gcd_num)

Submission status: Runtime Error

Solution code:
import math

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

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

C_bot = C * -(-A//C) 
C_top = C * (B//C) 
D_bot = D * -(-A//D)
D_top = D * (B//D)
CD_bot = lcm_CD * -(-A//(lcm_CD ))
CD_top = lcm_CD  * (B//(lcm_CD ))

num_A_B = B - A + 1
num_divC = (C_top - C_bot)//C + 1
num_divD = (D_top - D_bot)//D + 1
num_divCD = (CD_top - CD_bot)//(lcm_CD ) + 1
ans = num_A_B - num_divC - num_divD + num_divCD


print(int(ans))

Submission status: Runtime Error

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

import math

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

com = lcm(c,d)

total = b - a + 1
fir = int(b/c) - int((a-1)/c)
sec = int(b/d) - int((a-1)/d)
rem = int(b/com) - int((a-1)/com)

result = total - (fir + sec -rem)
  
print(result)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import time
import re
import math

def main():
    A,B,C,D=map(int,input().split())
    N=B-A+1
    sc=hoge(A,C)-A+1
    if sc<=N:
        ccount=math.floor((N+C-sc)/C)
    else:
       ccount=0

    sd=hoge(A,D)-A+1
    if sd<=N:
        dcount=math.floor((N+D-sd)/D)
    else:
       dcount=0

    CD=C * D / math.gcd(C, D)
    scd=hoge(A,CD)-A+1
    if scd<=N:
        cdcount=math.floor((N+CD-scd)/CD)
    else:
       cdcount=0
    print(N-(ccount+dcount-cdcount))


def hoge(a,b):
    return math.ceil(a/b)*b
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

def function(num_from, num_to , num):
	return (num_to // num) - ((num_from-1)// num)

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

result = (b - a + 1) - ((function(a,b,c) + function( a ,b, d) - function(a,b, c * d / math.gcd(c , d))))

print(int(result))

Submission status: Runtime Error

Solution code:
import math

A,B,C,D = map(int,input().split(" "))
min_C = int(B/C)-int((A-1)/C)
min_D = int(B/D)-int((A-1)/D)
lcm = int(C*D/math.gcd(C,D))
min_lcm = int(B/lcm)-int((A-1)/lcm)
print(B-A-min_C-min_D+min_lcm+1)

Submission status: Runtime Error

Solution code:
# C
import math

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

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

if A%D==0:
    x=A
else:
    x = A-A%D+D
if B%D==0:
    y=B
else:
    y = B-B%D
D_multi = (y-x)//D+1
# print(x)
# print(y)
# print(D_multi)

E = C * D / math.gcd(C,D)
if A%E==0:
    x=A
else:
    x = A-A%E+E
if B%E==0:
    y=B
else:
    y = B-B%E
E_multi = (y-x)//E+1

print(int(num-C_multi-D_multi+E_multi))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans = 0
for i in range(len(n_range)):
	if n_range[i] % c != 0 and n_range[i] % d != 0:
		ans += 1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

A, B, C, D = map(int,input().split())
CD = C * D / math.gcd(C, D)
numC = int(B/C) - int((A-1)/C)
numD = int(B/D) - int((A-1)/D)
numCD = int(B/(CD)) - int((A-1)/(CD))
print(B - A + 1 - (numC + numD - numCD))

Submission status: Runtime Error

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

sum1=(A-1)//C
sum2=B//C
sum3=sum2-sum1
sum1=(A-1)//D
sum2=B//D
sum4=sum2-sum1
num=(C*D)//math.gcd(C,D)
sum1=(A-1)//num
sum2=B//num
sum5=sum2-sum1
sum=sum3+sum4-sum5
sum=B-A+1-sum


print(sum)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import math
 
A, B, C, D = map(int, input().split())
sub = abs(A - B)
num1 , num2, num3 = (sub // C + 1), (sub // D + 1), (sub // (C * D // math.gcd(C, D))) + 1
        
print(sub - num1 - num2 + num3 + 1)

Submission status: Runtime Error

Solution code:
import math

A,B,C,D = map(int,input().split(" "))
min_C = int(B/C)-int((A-1)/C)
min_D = int(B/D)-int((A-1)/D)
lcm = C*D//math.gcd(C,D)
min_lcm = int(B/lcm)-int((A-1)/lcm)
print(B-A-min_C-min_D+min_lcm+1)

Submission status: Runtime Error

Solution code:
import math

a = input().split(" ")

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

min = min(C,D)
max = max(C,D)
gcd = (min*max)/math.gcd(min,max)

c_num = 0
if A%min == 0:
     c_num = int(B/min) - int(A/min) + 1
else:
    c_num = int(B/min) - int(A/min)

d_num = 0
if A%max == 0:
     d_num = int(B/max) - int(A/max) + 1
else:
    d_num = int(B/max) - int(A/max)


gcd_num = 0
if A%gcd == 0:
     gcd_num = int(B/gcd) - int(A/gcd) + 1
else:
    gcd_num = int(B/gcd) - int(A/gcd)


print(B-A+1-c_num-d_num+gcd_num)

Submission status: Runtime Error

Solution code:
import math
p=input().rstrip().split(' ')
a=int(p[0])
b=int(p[1])
c=int(p[2])
d=int(p[3])
e=(b//c)-(a//c)
if (a%c==0):
    e+=1;
f=(b//d) - (a//d);
if (a%d==0):
    f+=1;
g=b-a+1
h=math.gcd(c,d)
i=(c*d)//h
if i==0:
    j=0;
else:
    j=(b//i) - (a//i)
    if (a%i==0):
        j+=1;
k=e+f-j
l=g-k
print(l)

Submission status: Runtime Error

Solution code:
import math

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

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

def num_of_mod0(mod):
    if A%mod == 0:
        start = A
    else:
        start = (A//mod +1) * mod

    end = (B // mod) * mod

    return (end - start) / mod +1

ans =(B-A+1)-(num_of_mod0(C) + num_of_mod0(D)- num_of_mod0(lcm(C,D)))
ans = int(ans)
print(ans)

Submission status: Runtime Error

Solution code:
#c.py
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(a, b):
    return a * b / gcd(a,b)
a,b,c,d = map(int,input().split())
canC = int(b//c) -int((a-1)//c)
canD = int(b//d) - int((a-1)//d))
dbCD = int(b//lcm(c,d)) -int((a-1)//lcm(c,d))
print((b-a+1) -canC - canD + dbCD)

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

lcm = lcm(C, D)

minc = C*math.ceil(A/C)
maxc = C*math.floor(B/C)
mind = D*math.ceil(A/D)
maxd = D*math.floor(B/D)
minlcm = lcm*math.ceil(A/lcm)
maxlcm = lcm*math.floor(B/lcm)

nc = int( ( (maxc - minc)/C ) + 1 )
nd = int( ( (maxd - mind)/D ) + 1 )
nlcm = int( ( (maxlcm - minlcm)/lcm ) + 1 )

if minc > maxc:
    nc = 0
if mind > maxd:
    nd = 0
if minlcm > maxlcm:
    nlcm = 0

n = B - A + 1 - nc - nd + nlcm

print(n)

Submission status: Runtime Error

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

i = ((b- a)//c)+1
j = ((b- a)//d)+1

f=math.gcd(c,d)
k = c*d//f

count = i + j - f

print(b-a+1-count)

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
import math
import fractions
nc=math.floor((b-a)/c)
nd=math.floor((b-a)/d)
lcd=c*d//math.gcd(c,d)
ncd=math.floor((b-a)/lcd)
sum=nc+nd-ncd
print(b-a-sum)

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

lcm = lcm(C, D)
#print(lcm)

minc = C*math.ceil(A/C)
maxc = C*math.floor(B/C)
mind = D*math.ceil(A/D)
maxd = D*math.floor(B/D)
minlcm = lcm*math.ceil(A/lcm)
maxlcm = lcm*math.floor(B/lcm)

nc = int( ( (maxc - minc)/C ) + 1 )
nd = int( ( (maxd - mind)/D ) + 1 )
nlcm = int( ( (maxlcm - minlcm)/lcm ) + 1 )

#print()
#print(minc,maxc)
#print(mind,maxd)
#print(minlcm,maxlcm)
#print()
#print(nc,nd,nlcm)

if minc > maxc:
    nc = 0
if mind > maxd:
    nd = 0
if minlcm > maxlcm:
    nlcm = 0

n = B - A + 1 - nc - nd + nlcm

print(n)

Submission status: Runtime Error

Solution code:
def sol(inp=input):
    import math
    a,b,c,d=map(int,inp().split())
    def fix_min(b):
        c_=b//c
        d_=b//d
        cd_=b//(c*d//math.gcd(c,d))
        return b-c_-d_+cd_
    return fix_min(b)-fix_min(a-1)
print(sol())

Submission status: Runtime Error

Solution code:
import math
num = input().split(" ")
a = int(num[0])-1
b = int(num[1])
c = int(num[2])
d = int(num[3])
e = c * d // int(math.gcd(c, d))
aaa = b - (b//c) -(b//d) +(b//e) -(a -(a//c) -(a//d) + (a//e))
print(int(aaa))

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)
if a%c==0:
    wari_c=int(b//c-a//c+1)
else:
    wari_c=int(b//c-a//c)
if a%d==0:
    wari_d=int(b//d-a//d+1)
else:
    wari_d=int(b//d-a//d)
if a%c_d==0:
    wari_c_d=int(b//c_d-a//c_d+1)
else:
    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:
# coding: utf-8
# Your code here!
import numpy as np
import math

A, B, C, D = map(int, input().split())
sub = abs(A - B)
num1 , num2, num3 = (sub // C + 1), (sub // D + 1), (sub // (C * D // math.gcd(C, D))) + 1
print(num1, num2, num3)
        
print(sub - num1 - num2 + num3 + 1)