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:
A,B,C,D=map(int,input().split())
setAB=set(range(A,B+1))
setC=set(range(A,B+1,C))
setD=set(range(A,B+1,D))
setCD=setC.union(setD)
setANS=setAB-setCD
ans=len(setANS)
print(ans)

Submission status: Wrong Answer

Solution code:
A , B , C , D = map(int, input().split())
hani = B - A + 1
if C == 1:
    Cdiv = hani
else:
    Cdiv = (B + 1) // C - A // C
if D == 1:
    Ddiv = hani
else:
    Ddiv = (B + 1) // D - A // D
def gcd(x, y):
    if x < y:
        tmp = x
        x = y
        y = tmp
    r = x % y   
    while r != 0:
        x = y
        y = r
        r = x % y
    return y
LCM = (C * D) // gcd(C, D)
LCMdiv = (B + 1) // LCM - A // LCM
ans = hani - Cdiv - Ddiv + LCMdiv
print(ans)

Submission status: Wrong Answer

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

mi = min(c, d)
ma = max(c, d)

l = int(mi ** (1 / 2)) + 1
s = l + 1
for i in range(1, l + 1):
    if ((ma * i) % mi == 0):
        s = i
        break
if s == l + 1:
    s = mi

e = ma * s
cl = a // c + 1 if a % c != 0 else a // c
dl = a // d + 1 if a % d != 0 else a // d
el = a // e + 1 if a % e != 0 else a // e
ch = b // c
dh = b // d
eh = b // e

print(b - a - (ch - cl + dh - dl) + eh - el)

Submission status: Wrong Answer

Solution code:
import fractions
s = input().split()
A = int(s[0])
B = int(s[1])
C = int(s[2])
D = int(s[3])
count = 0
C_value = B//C -(A-1)//C
D_value = B//D -(A-1)//D
value = B//(fractions.gcd(C, D)) - (A-1)//(fractions.gcd(C, D))
print(B-(A-1)-(C_value + D_value - value))

Submission status: Wrong Answer

Solution code:
#S=input()
import fractions

lis=list(map(int,input().split()))
gCD=fractions.gcd(lis[2],lis[3])
CD=int(lis[2]*lis[3]/gCD)
AmodC=lis[0]%lis[2]
if AmodC==0:
    AC=lis[0]
else:
    AC=lis[0]+(lis[2]-AmodC)
AmodD=lis[0]%lis[3]
if AmodD==0:
    AD=lis[0]
else:
    AD=lis[0]+(lis[3]-AmodD)
BmodC=lis[1]%lis[2]
if BmodC==0:
    BC=lis[1]
else:
    BC=lis[1]+(lis[2]-BmodC)
BD=lis[1]-lis[1]%lis[3]
ACD=lis[0]+(CD-lis[0]%CD)
BCD=lis[1]-lis[1]%CD
ABC=(BC-AC)/lis[2]+1
ABD=(BD-AD)/lis[3]+1
ABCD=(BCD-ACD)/CD+1
ans=lis[1]-lis[0]+1-int(ABC+ABD-ABCD)

print(ans)

Submission status: Wrong Answer

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

def c_in_a2b(c):
    return (B//c - A//c)
print((B-A)- c_in_a2b(C)-c_in_a2b(D)+c_in_a2b(C*D))

Submission status: Wrong Answer

Solution code:
A, B, C, D =  (int(j) for j in input().split()) 
if C > D:
  d = D
  D = C
  C = D
    
n = B - A + 1
CD = C * D
if C != D:
  print( n- ( (B//C - (A-1)//C) + (B//D - (A-1)//D) - (B//CD - (A-1)//CD) ) )
else:
  print( n- ( (B//C - (A-1)//C) ) )

Submission status: Wrong Answer

Solution code:
# import math
#
#
inp = input()
split_inp = inp.split()
a = int(split_inp[0])
b = int(split_inp[1])
c = int(split_inp[2])
d = int(split_inp[3])
#
#
def gcd(a, b):
    if a < b:
        c = a
        a = b
        b =c
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
    return b


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

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

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

# print(lcm(15, 20))

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

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int, input().split())
ab=b-a
C=ab//c+1 if a%c==0 and b%c==0 else ab//c
D=ab//d+1 if a%d==0 and b%d==0 else ab//d
e=c*d//fractions.gcd(c, d)
E=ab//e+1 if a%e==0 and b%e==0 else ab//e
ans=ab-C-D+E
print(ans)

Submission status: Wrong Answer

Solution code:

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

def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table


#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)


sais = lcm(C, D)

buff_a = A - 1


sais_mx = B // sais
sais_mm = buff_a // sais
sais_count = sais_mx + sais_mm

c_mx = B // C
c_mm = buff_a // C
c_count = c_mx - c_mm

d_mx = B // D
d_mm = buff_a // D
d_count = d_mx - d_mm

# print("c d")
# print(c_count, d_count)
zentai = c_count + d_count

zentai = zentai - (sais_count*2)

b_a = B - A
ans = b_a - zentai
# print(zentai)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
A, B, C, D = map(int, input().split())
num_list = B - A + 1
C_start = int((A/C)+0.99)
C_end = int(B/C)
C_num = C_end - C_start + 1
D_start = int((A/D)+0.99)
D_end = int(B/D)
D_num = D_end - D_start + 1
lcm = C*D/fractions.gcd(C, D)
lcm_start = int((A/lcm)+0.99)
lcm_end = int(B/lcm)
lcm_num = lcm_end - lcm_start + 1
print(num_list-C_num-D_num+lcm_num)

Submission status: Wrong Answer

Solution code:
import numpy as np
a = input()
a, b, c, d = [int(i) for i in a.split(" ")]
num = np.array([i for i in range(a, b)])
print((num % (c * d) == 0).sum())

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[129]:


import fractions


# In[124]:


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


# In[137]:


lcm = int(C*D / fractions.gcd(C, D))


# In[138]:


c_part_a = int(A / C)
d_part_a = int(A / D)
cd_part_a = int(A / lcm)

c_part_b = int(B / C)
d_part_b = int(B / D)
cd_part_b = int(B / lcm)


# In[139]:


ans1 = (A-1) - (c_part_a + d_part_a - cd_part_a)
ans2 = B - (c_part_b + d_part_b - cd_part_b)


# In[140]:


print(ans2 - ans1)


# In[ ]:

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
def calc(x):
    cnt=int((B-A)/x)
    if B%x==0:
        cnt+=1
    elif A%x==0:
        cnt+=1
    return int(cnt)
def gcd(m,n):
    if n==0:
        return m
    else:
        return gcd(n,m%n)
def lcm(m,n):
    return int(m*n/gcd(m,n))
print(B-A+1-calc(C)-calc(D)+calc(lcm(D,C)))

Submission status: Wrong Answer

Solution code:
import fractions

A,B,C,D=map(int,input().split())
num=B-A
numC=num//C
numD=num//D
numCD=int(num//(C*D/fractions.gcd(C,D)))
ans=num-numC-numD+numCD
print(ans)

Submission status: Wrong Answer

Solution code:
#S=input()
import fractions

lis=list(map(int,input().split()))
gCD=fractions.gcd(lis[2],lis[3])
CD=int(lis[2]*lis[3]/gCD)
AmodC=lis[0]%lis[2]
if AmodC==0:
    AC=lis[0]
else:
    AC=lis[0]+(lis[2]-AmodC)
AmodD=lis[0]%lis[3]
if AmodD==0:
    AD=lis[0]
else:
    AD=lis[0]+(lis[3]-AmodD)
BmodC=lis[1]%lis[2]
if BmodC==0:
    BC=lis[1]
else:
    BC=lis[1]+(lis[2]-AmodC)
BD=lis[1]-lis[1]%lis[3]
ACD=lis[0]+(CD-lis[0]%CD)
BCD=lis[1]-lis[1]%CD
ABC=(BC-AC)/lis[2]+1
ABD=(BD-AD)/lis[3]+1
ABCD=(BCD-ACD)/CD+1
ans=lis[1]-lis[0]+1-int(ABC+ABD-ABCD)

print(ans)

Submission status: Wrong Answer

Solution code:

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

def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table


#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)


sais = lcm(C, D)

buff_a = A - 1


sais_mx = B // sais
sais_mm = buff_a // sais
sais_count = sais_mx + sais_mm

c_mx = B // C
c_mm = buff_a // C
c_count = c_mx - c_mm

d_mx = B // D
d_mm = buff_a // D
d_count = d_mx - d_mm

print("c d")
print(c_count, d_count)
zentai = c_count + d_count

zentai = zentai - (sais_count*2)

b_a = B - A
ans = b_a - zentai
print(zentai)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

A, B, C, D = map(int, input().split())
E = C * D // gcd(C, D)

divc = ceil((B + 1)/C) - ceil(A / C)
divd = ceil((B + 1)/D) - ceil(A / D)
dive = ceil((B + 1)/E) - ceil(A / E)
print(B - A - (divc + divd - dive) + 1)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
	if b==0:
		return a
	else:
		return gcd(b, a%b)
def lmc(a, b):
	return a*(b//gcd(a, b))

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

l = ((a+c-1)//c)*c-1
r = (b//c)*c
k1 =(r-l)//c+1

l = ((a+d-1)//d)*d-1
r = (b//d)*d
k2 =(r-l)//d+1

w = lmc(c, d)
l = ((a+w-1)//w)*w-1
r = (b//w)*w
k3 =(r-l)//w+1

ans = (b-a+1)-(k1+k2-k3)
print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
a,b,c,d=list(map(int,input().split(" ")))
g=gcd(c,d)
cd=c*d
Ncd=int(b/(cd/g))-int(a/(cd/g))
Nc=int(b/c)-int(a/c)
Nd=int(b/d)-int(a/d)
print(b-a-(Nc+Nd-Ncd))

Submission status: Wrong Answer

Solution code:
def _gcd(x, y):
    x = abs(x)
    y = abs(y)
    while y:
        x, y =  y, x % y
    return x

def _lcm(x, y):
    x = abs(x)
    y = abs(y)
    return (x * y / _gcd(x, y))
  
A,B,C,D=map(int, input().split())

cc = (B//C)-((A-1)//C)
dd = (B//D)-((A-1)//D)

x = _lcm(C,D)
ee = (B//x)-((A-1)//x)

ans = (B-A+1)-(cc + dd - ee)
print(int(ans))

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
def lcm(a,b):
  return a*b//gcd(a,b)

a,b,c,d=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
x=a+a%c
y=a+a%d
e=lcm(c,d)
z=a+a%e
x2=(b-x)//c+1
y2=(b-y)//d+1
z2=(b-z)//e+1
if e>b:
    print("f")
else:
    print(b-a-x2-y2+z2+1)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int, input().split())
ab=b-a
C=ab//c if a%c!=0 and b%c!=0 else ab//c+1
D=ab//d if a%d!=0 and b%d!=0 else ab//d+1
e=c*d//fractions.gcd(c, d)
E=ab//e if a%e!=0 and b%e!=0 else ab//e+1
ans=ab-C-D+E
print(ans)

Submission status: Wrong Answer

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

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

print(count)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
if A%C==0 and A%D==0:
    C_div = (B-A+1)//C + 1
else:
    C_div = (B-A+1)//C
if B%C==0 and B%D==0:
    D_div = (B-A+1)//D + 1
else:
    D_div = (B-A+1)//D
if A%(C*D) == 0 and B%(C*D) == 0:
    CD_div = (B-A+1)//(C*D) + 1
else:
    CD_div = (B-A+1)//(C*D)

print((B-A+1) - C_div -D_div + CD_div)

Submission status: Wrong Answer

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

import fractions
import math

x = b//c - math.ceil(a/c) + 1
y = b//d - math.ceil(a/d) + 1
e = int(c*d)//int(fractions.gcd(c,d))
z = b//e - math.ceil(a/e) + 1

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

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
m = c* d / fractions.gcd(c,d)
x=0
x=(b//c-a//c)+(b//d-a//d)-(b//m-a//m)
print(int(x))

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    a, b, c, d = MAP()
    l=c*d/gcd(c,d)
    a-=1
    kukan1 = b - int(b / c) - int(b / d) + int(b / l)
    kukan2 = a - int(a / c) - int(a / d) + int(a / l)

    print(kukan1-kukan2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math, fractions
a,b,c,d = map(int,input().split())
x = math.floor(b/c) - math.ceil(a/c) + 1
y = math.floor(b/d) - math.ceil(a/d) + 1
g = c * d // fractions.gcd(c,d)
z = math.floor(b/g) - math.ceil(a/g) + 1
print(b-a+1-(x+y-z))

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int, input().split())
ans=B-A+1
E=C*D

if A%C==0:
    nC_initial=A//C
else:
    nC_initial=A//C+1
    
if A%D==0:
    nD_initial=A//D
else:
    nD_initial=A//D+1

    
if A%E==0:
    nE_initial=A//E
else:
    nE_initial=A//E+1
    
nC_final=B//C
nD_final=B//D
nE_final=B//E
if nC_final<nC_initial:
    nC_final=nC_initial
if nD_final<nD_initial:
    nD_final=nD_initial
if nE_final<nE_initial:
    nE_final=nE_initial
#print(ans,nC_initial,nC_final,nD_initial,nD_final, nE_initial,nE_final)
print(ans-(nC_final-nC_initial+1)-(nD_final-nD_initial+1)+(nE_final-nE_initial+1))

Submission status: Wrong Answer

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

C_ = int(B/C) - int(A/C)
if A % C == 0:                                                                                                                                                                                              
    C_ += 1                                                                                                                                                                                                 
D_ = int(B/D) - int(A/D)
if A % D == 0:                                                                                                                                                                                              
    D_ += 1                                                                                                                                                                                                 

E = C * D / int(fractions.gcd(C, D))
E_ = int(B/E) - int(A/E)
if A % E == 0:                                                                                                                                                                                              
    E_ += 1                                                                                                                                                                                                 

ans = B - A + 1 - C_ - D_ + E_
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

inp = [int(i) for i in input().split()]
c1 = (inp[0]-1) // inp[2]
c2 = inp[1] // inp[2]
c = c2 - c1

d1 = (inp[0]-1) // inp[3]
d2 = inp[1] // inp[3]
d = d2 -d1

e1 = inp[0] // (inp[3] * inp[2]/fractions.gcd(inp[3],inp[2]))
e2 = inp[1] // (inp[3] * inp[2]/fractions.gcd(inp[3],inp[2]))
e = e2 - e1

print(int(inp[1]-inp[0]+1-(c+d-e)))

Submission status: Wrong Answer

Solution code:
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A


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


if __name__ == '__main__':
    A, B, C, D = InputToInt()
    ALL = B-A+1
    Cdiv = int(B/C) - int((A-1)/C)
    Ddiv = int(B/D) - int((A-1)/D)
    lcm = C*D/gcd(C, D)
    LCMdiv = int(B/lcm) - int((A-1)/lcm)
    print(ALL - Cdiv - Ddiv + LCMdiv)

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 = map(int,input().split())
a1 = a//c
a2 = b//c
a3 = a2 - a1 - 1

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

width = b - a + 1

print(width - a3 - b3)

Submission status: Wrong Answer

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

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


countC = B // C - A // C
if A % C == 0:
    countC += 1
countD = B // D - A // D
if A % D == 0:
    countD += 1
s = gcd(C, D)
countCD = B // C // (D // s) - A // C // (D // s)
if A / C / (D // s) == 1:
    countCD += 1
print(B - A + 1 - countC - countD + countCD)

Submission status: Wrong Answer

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

a1, b, c, d = map(int, input().split())
a = a1 - 1
Sa = a - a//c - a//d + a//(c*d/gcd(c, d))
Sb = b - b//c - b//d + b//(c*d/gcd(c, d))
print(int(Sb - Sa))

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
if A%C==0 and A%D==0:
    C_div = (B-A+1)//C + 1
else:
    C_div = (B-A+1)//C
if B%C==0 and B%D==0:
    D_div = (B-A+1)//D + 1
else:
    D_div = (B-A+1)//D
if A%(C*D) == 0 and B%(C*D) == 0:
    CD_div = (B-A+1)//(C*D) + 1
else:
    CD_div = (B-A+1)//(C*D)
if C == 1 or D == 1:
    print(0)
else:
    print((B-A+1) - C_div -D_div + CD_div)

Submission status: Wrong Answer

Solution code:
#S=input()
import fractions

lis=list(map(int,input().split()))
gCD=fractions.gcd(lis[2],lis[3])
CD=int(lis[2]*lis[3]/gCD)
AmodC=lis[0]%lis[2]
if AmodC==0:
    AC=lis[0]
else:
    AC=lis[0]+(lis[2]-AmodC)
AmodD=lis[0]%lis[3]
if AmodD==0:
    AD=lis[0]
else:
    AD=lis[0]+(lis[3]-AmodD)
BC=lis[1]-lis[1]%lis[2]
BD=lis[1]-lis[1]%lis[3]
ACD=lis[0]+(CD-lis[0]%CD)
BCD=lis[1]-lis[1]%CD
ABC=(BC-AC)/lis[2]+1
ABD=(BD-AD)/lis[3]+1
ABCD=(BCD-ACD)/CD+1
ans=lis[1]-lis[0]+1-int(ABC+ABD-ABCD)

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d = map(int, input().split())
def sakana(x):
    e = int((a-1)/x)
    f = int(b/x)
    g = int(f - e)
    return g
m = sakana(c)
n = sakana(d)
o = sakana(c*d//fractions.gcd(c,d))
print(b-a+1-(m+n-o))

Submission status: Wrong Answer

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

C2 = (B // C) - ((A - 1) // C)
D2 = (B // D) - ((A - 1) // D)

#CD = lcm(C, D)

#CD2 = (B // CD) - ((A - 1) // CD)

#print(sa - (C2 + D2 - CD2))
print(sa - (C2 + D2))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
m = c* d / fractions.gcd(c,d)
x=0
x=(b//c-a//c)+(b//d-a//d)-(b//m+a//m)
print(int(x))

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
a,b,c,d = map(int,input().split())
m = int(c*d/gcd(c,d))
if a%c < b%c:
  xc = (b-a+1)//c
elif a%c > b%c and b%c == 0:
  xc = (b-a+1)//c
elif a%c > b%c:
  xc = (b-a+1)//c +1
elif a%c == b%c and a%c == 0:
  xc = (b-a+1)//c +1
else:
  xc  = (b-a+1)//c

if a%d < b%d:
  xd = (b-a+1)//d
elif a%d > b%d and b%d == 0:
  xd = (b-a+1)//d
elif a%d > b%d:
  xd = (b-a+1)//d +1
elif a%d == b%d and a%d == 0:
  xd = (b-a+1)//d +1
else:
  xd  = (b-a+1)//d

if a%m < b%m:
  xm = (b-a+1)//m
elif a%m > b%m and b%m == 0:
  xm = (b-a+1)//m
elif a%m > b%m:
  xm = (b-a+1)//m +1
elif a%m == b%m and a%m == 0:
  xm = (b-a+1)//m +1
else:
  xm  = (b-a+1)//m

print(b-a+1-xc-xd+xm)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
def lcm(a,b):
  return a*b//gcd(a,b)

a,b,c,d=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
x=a+a%c
y=a+a%d
e=lcm(c,d)
z=a+a%e
x2=(b-x)//c+1
y2=(b-y)//d+1
z2=(b-z)//e+1
if e>b:
    print(b-a-x2-y2+1)
else:
    print(b-a-x2-y2+z2+1)

Submission status: Wrong Answer

Solution code:
import sys

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


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


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


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

Submission status: Wrong Answer

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

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

#最小公倍数
def lcm(a,b):
  return a*b//gcd(a,b)
lcm = lcm(C,D)

fst = B//C - (A-1)//C
snd = B//D - (A-1)//D
if A-1 < lcm:
  dlt = B//lcm
else:
  dlt = B//lcm - (A-1)//D

print(B-A+1 - (fst+snd-dlt))

Submission status: Wrong Answer

Solution code:

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

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

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

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

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

print(B-A+1-total)

Submission status: Wrong Answer

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)

	#else:
		#print('warikireru')

print(len(ans))

Submission status: Wrong Answer

Solution code:
import fractions
a = list(map(int, input().split()))
n = a[1]-a[0]+1
wac = int(a[1]/a[2])-int(a[0]/a[2])

if a[0]%a[2]==0:
    wac+=1
wad= int(a[1]/a[3])-int(a[0]/a[3])

if a[0]%a[3]==0:
    wad+=1
lcm = a[2]*a[3]//fractions.gcd(a[2], a[3])
cd = int(a[1]/lcm)-int(a[0]/lcm)

if a[0]%lcm==0:
    cd +=1

print(n-wac-wad+cd)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[123]:


import fractions


# In[124]:


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


# In[125]:


lcm = int(C*D / fractions.gcd(C, D))


# In[126]:


c_part_a = int((A - 1) / C)
d_part_a = int((A - 1) / D)
cd_part_a = int((A - 1) / lcm)

c_part_b = int(B / C)
d_part_b = int(B / D)
cd_part_b = int(B / lcm)


# In[127]:


ans1 = (A-1) - (c_part_a + d_part_a - cd_part_a)
ans2 = B - (c_part_b + d_part_b - cd_part_b)


# In[128]:


print(ans2 - ans1)


# In[ ]:

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
t = b//c-a//c
u = b//d-a//d
if a%c == 0:
  t += 1
if a%d == 0:
  if c != d:
    u += 1
def gcd(p,q):
    if p%q != 0:
        return gcd(q,p%q)
    else:
        return q
k = c*d//gcd(c,d)
v = b//k-a//k
if a != b:
  if c != 1 and d != 1:
    print(b-a+1-t-u+v)
  else:
    print(0)
else:
  if a%c == 0:
    print(0)
  elif a%d == 0:
    print(0)
  else:
    print(1)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
a,b,c,d = map(int,input().split())
m = int(c*d/gcd(c,d))
if a%c < b%c:
  xc = (b-a+1)//c
elif a%c > b%c and b%c == 0:
  xc = (b-a+1)//c
elif a%c > b%c:
  xc = (b-a+1)//c +1
elif a%c == b%c and a%c == 0:
  xc = (b-a+1)//c +1
else:
  xc  = (b-a+1)//c

if a%d < b%d:
  xd = (b-a+1)//d
elif a%d > b%d and b%d == 0:
  xd = (b-a+1)//d
elif a%d > b%d:
  xd = (b-a+1)//d +1
elif a%d == b%d and a%d == 0:
  xd = (b-a+1)//d +1
else:
  xd  = (b-a+1)//d

if a%m < b%m:
  xm = (b-a+1)//m
elif a%m > b%m and b%m == 0:
  xm = (b-a+1)//m
elif a%m > b%m:
  xm = (b-a+1)//m +1
elif a%m == b%m and a%m == 0:
  xm = (b-a+1)//m +1
else:
  xm  = (b-a+1)//m

print("{} {} {}".format(xc,xd,xm))
print(b-a+1-xc-xd+xm)

Submission status: Wrong Answer

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

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

width = b - a + 1

print(a3,b3)

print(width - a3 - b3)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

if C > D :
    C , D = D , C

ans = 0

if A < C :
    ans += C - A
    A = C

# 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 = C * D / fractions.gcd(C,D)

ans += B - A + 1 - countX(C) - countX(D) + countX(Z)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A,B,C,D = map(int, input().split())
cnt = 0
x = (A-1) // C
xx = B // C
y = (A-1) // D
yy = B // D
E = C*D / gcd(C,D)
z = (A-1) // E
zz = B // E
tmp = xx-x + yy-y - (zz-z)
print(int(B-A - tmp))
# print(B-A, xx-x,yy-y,zz-z, tmp, cnt)

Submission status: Wrong Answer

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

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

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

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

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


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

Submission status: Wrong Answer

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

# b以下の数でcでもdでも割り切れない数を数える
b_ika = b-b//c-b//d+b//(c*d)
#a未満の数でcでもdでも割り切れない数を数える
a_miman = (a-1)-(a-1)//c-(a-1)//d+(a-1)//(c*d)

print(b_ika-a_miman)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    a, b, c, d = MAP()
    l=gcd(c,d)*c*d
    a-=1
    kukan1 = b - int(b / c) - int(b / d) + int(b / l)
    kukan2 = a - int(a / c) - int(a / d) + int(a / l)

    print(kukan1-kukan2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
l=list(map(int,input().split()))
aa=(l[1]-l[0]+1)
ans=aa-((aa//l[2])+(aa//l[3])-(aa//l[2]//l[3]))
print(ans)

Submission status: Wrong Answer

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

lcm= c*d/fractions.gcd(c,d)
a_c = (a-1)//c
b_c = b//c
a_d = (a-1)//d
b_d = b//d
a_cd = (a-1)//(lcm)
b_cd = b//(lcm)


ans = b-a+1-((b_c-a_c)+(b_d-a_d)-(b_cd-a_cd))
print(int(ans))

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int, input().split())
ans=B-A+1
E=C*D

if A%C==0:
    nC_initial=A//C
else:
    nC_initial=A//C+1
    
if A%D==0:
    nD_initial=A//D
else:
    nD_initial=A//D+1

    
if A%E==0:
    nE_initial=A//E
else:
    nE_initial=A//E+1
    
nC_final=B//C
nD_final=B//D
nE_final=B//E
if nE_final<nE_initial:
    nE_final=nE_initial
#print(ans,nC_initial,nC_final,nD_initial,nD_final, nE_initial,nE_final)
print(ans-(nC_final-nC_initial+1)-(nD_final-nD_initial+1)+(nE_final-nE_initial+1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	#S = int(input())
	#S = list(input())
	A,B,C,D = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))

	E = lcm(C, D)

	tmp_C2 = B // C
	tmp_C2ama = B % C
	tmp_D2 = B // D
	tmp_D2ama = B % D
	tmp_C1 = A // C
	tmp_C1ama = A % C
	tmp_D1 = A // D
	tmp_D1ama = A % D

	tmp_E2 = B // E
	tmp_E2ama = B % E
	tmp_E1 = A // E
	tmp_E1ama = A % E

	
	#print("{} {} {} {} {} {}".format(tmp_C2ama, tmp_D2ama, tmp_C1ama, tmp_D1ama, tmp_E2ama, tmp_E1ama))

	tmp = (tmp_C2+tmp_D2)-(tmp_C1+tmp_D1)

	tmp2 = 0
	if tmp_C1ama == 0:
		tmp2 -=1
	if tmp_D1ama == 0:
		tmp2 -=1
	#print(tmp2)

	ans = B-A-tmp+1+(tmp_E2-tmp_E1)+tmp2

	
	print(ans)

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

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

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
count = 0
area = B-A+1
count += int(area/C)
if (B%C + A%C) >=C:
    count+=1
count += int(area/D)
if (B%D + A%D) >=D:
    count+=1
E = C*D
count -= int(area/E)
if (B%E + A%E) >=E:
    count-=1

print(area-count)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

rng = B - A

count = B - A + 1

if A <= C * A // C and  C * A // C <= B:
  count -= (B - C * A // C) // C + 1

if A <= D * A // D and D * A // D  <= B:
  count -= (B - D * A // D) // D + 1

C_D_lcm = lcm(C, D)

if A <= C_D_lcm * A // C_D_lcm and  C_D_lcm * A // C_D_lcm <= B:
  count += (B - C_D_lcm * A // C_D_lcm) // C_D_lcm + 1

print(count)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
e=0
f=0
g=0
if(a%c!=0):
    e=(b//c)-(a//c)
else:
    e=(b//c)-(a//c)+1
if(a%d!=0):
    f=(b//d)-(a//d)
else:
    f=(b//d)-(a//d)+1
if(a%(c*d)!=0):
    g=(b//(c*d))-(a//(c*d))
else:
    g=(b//(c*d))-(a//(c*d))+1
print('{0}'.format(b-a+1-e-f+g))

Submission status: Wrong Answer

Solution code:
def main():

    # 1 <= a <= b <= 10^18
    # 1 <= c,d <= 10^9

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

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

    print(count)

if __name__ == '__main__':
    main()