Problem:


Score : 300 points

Problem Statement

You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Constraints

1\leq A\leq B\leq 10^{18}

1\leq C,D\leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Sample Input 1

4 9 2 3

Sample Output 1

2

5 and 7 satisfy the condition.

Sample Input 2

10 40 6 8

Sample Output 2

23

Sample Input 3

314159265358979323 846264338327950288 419716939 937510582

Sample Output 3

532105071133627368



Sample input:
4 9 2 3


Sample output:
2

Submission status: Wrong Answer

Solution code:
import math

def gcd(x,y):
  M=max(x,y)
  m=min(x,y)
  while(M%m!=0):
      r=M%m
      M=m
      m=r
  return m



def f(x,y):
  z=math.floor(x//y)
  return z


a,b,c,d=map(int,input().split())
g=gcd(c,d)
p=a-f(a,c)-f(a,d)+f(a,c*d/g)
q=b-f(b,c)-f(b,d)+f(b,c*d/g)
if(a%c!=0 and a%d!=0):
  print(q-p+1)
else:
  print(q-p)

Submission status: Wrong Answer

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

            e=e+1

for n in range(int(b)):
    if (n+1)%int(c)!=0:
        if (n+1)%int(d)!=0:
            f=f+1


print(f-e)

Submission status: Wrong Answer

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

def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

lcm = C*D / gcd(C,D)
AC = A//C
AD = A//D
A_lcm = A//lcm
A_num = AC+AD-A_lcm

BC = B//C
BD = B//D
B_lcm = B//lcm
B_num = BC+BD-B_lcm

if A%C * A%D ==0:
  print((B-A) - (B_num-A_num))
else:
  print((B-A) - (B_num-A_num) + 1)

Submission status: Wrong Answer

Solution code:
import fractions

def lcm(x, y):
    return (x * y) // fractions.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: Wrong Answer

Solution code:
import fractions
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) / fractions.gcd(c,d)))

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *
readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

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

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

a, b, c, d = readmi()
t1 = b // c - (a - 1) // c
t2 = b // d - (a - 1) // d
ans = t1 + t2
l = lcm(c, d)
if b >= l >= a:
    ans -= b // l - (a - 1) // l
print(b - a + 1 - ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
from fractions import gcd
inputs = sys.stdin.readlines()
a, b, c, d = [int(x) for x in inputs[0].split(' ')]

if c <= a:
    for i in range(a, b+1):
        if i % c == 0:
            break
elif a <= c <= b:
    i = c
else:
    i = b+1
c_ = math.ceil((b+1 - i) / c)

if d <= a:
    for i in range(a, b+1):
        if i % d == 0:
            break
elif a <= d <= b:
    i = d
else:
    i = b+1

d_ = math.ceil((b+1 - i) / d)

e = c * d // gcd(c, d) # lcm(c, d)
if e <= a:
    for i in range(a, b+1):
        if i % e == 0:
            break
elif a <= e <= b:
    i = e
else:
    i = b+1

e_ = math.ceil((b+1 - i) / e)

print(b+1 - a - c_ - d_ + e_)

Submission status: Wrong Answer

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


def gcd(x, y):
    x = abs(x)
    y = abs(y)
    while y:
        x, y = y, x % y
    return x

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

def Ndivingcd(x, y, i):
    if x==y:
        return i-(int)(i/x)
    else:
        return i - (int)(i / x) - (int)(i / y)

CDgcd = lcm(C,D)
Ningcd = CDgcd - (int)(CDgcd/C) - (int)(CDgcd/D) +1
Nloop = math.floor(B / CDgcd)-math.floor(A / CDgcd)
firstgcd = math.floor(A / CDgcd)*CDgcd
lastgcd  = math.floor(B / CDgcd)*CDgcd
NdivtoA=0
if not A==firstgcd:
    NdivtoA = Ndivingcd(C,D,A-firstgcd-1)
NdivtoB = Ndivingcd(C,D,B-lastgcd)
N = Nloop*Ningcd+NdivtoB-NdivtoA
print(N)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, 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)


ac = int(A / C)
bc = int(B / C)
ad = int(A / D)
bd = int(B / D)
acd = int(A / lcm(C, D))
bcd = int(B / lcm(C, D))

if A % C == 0:
    c_div = bc - ac + 1
else:
    c_div = bc - ac
if A % D == 0:
    d_div = bd - ad + 1
else:
    d_div = bd - ad
if A % lcm(C, D) == 0:
    cd_div = bcd - acd + 1
else:
    cd_div = bcd - acd

print(B - A + 1 - c_div - d_div + cd_div)

Submission status: Wrong Answer

Solution code:
import fractions

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

G = C*D//fractions.gcd(C,D)

Conly = 1 + ( ( B - (B%C) ) - ( A + C - (A%C) ) ) // C
Donly = 1 + ( ( B - (B%D) ) - ( A + C - (A%D) ) ) // D
CandD = 1 + ( ( B - (B%G) ) - ( A + C - (A%G) ) ) // G

if C == 1 or D==1:
  result = 0
else:
  result = B - A + 1 - ( Conly + Donly - CandD )

print(result)

Submission status: Wrong Answer

Solution code:
import math

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

_c = c
_d = d
if (_c > _d) :
	tmp = _d
	_d = _c
	_c = tmp
while _d % _c != 0:
	_d, _c = _c, _d % _c
cd = (c * d) // _c

_a = int(a/c) + int(a/d) - int(a/cd);
_b = int(b/c) + int(b/d) - int(b/cd);
ans = (b - a) - (_b - _a);

if (a%c != 0 and a%d != 0) : ans +=1

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D=map(int,input().split())
X=0
L=0
M=0
N=0
E=C*D//fractions.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(X)

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
from fractions import gcd

a,b,c,d = getList()
def rui(a, c, d):
    cwari = a // c
    dwari = a // d
    cd = c * d / gcd(c, d)
    cdwari = a // cd
    return int(a - (cwari + dwari - cdwari))

ra = (rui(b,c,d))
rb = ((rui(a-1,c,d)))
print(ra - rb)

Submission status: Wrong Answer

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

A -= 1

A_C = A // C
A_D = A // D
A_Z = A // (C * D)

A_num = A - ( A_C + A_D - A_Z )

B_C = B // C
B_D = B // D
B_Z = B // (C * D)

B_num = B - ( B_C + B_D - B_Z )


print(B_num - A_num)

Submission status: Wrong Answer

Solution code:
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%(c*d) :
  f-=1
  
print( n - int(n/d) - int(n/c) + int(n/(d*c) - f))

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)
ans=len(setAB)-len(setCD)
print(ans)

Submission status: Wrong Answer

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

a, b, c, d = map(int, input().split())
num = 0
cd = c*d/(gcd(c,d))
s = b - a + 1
s_c = int(s/c)
s_d = int(s/d)
s_cd = int(s/cd)
if(a%c >= b%c):
  num = num + 1
if(a%d >= b%d):
  num = num + 1
if(a%cd >= b%cd):
  num = num - 1
print(s -(s_c + s_d - s_cd) - num)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

ans = B - A + 1

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

    return maxX - minX + 1

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

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

print(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 = 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/gcd(C,D))
min_lcm = int(B/lcm)-int((A-1)/lcm)
print(B-A-min_C-min_D+min_lcm+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 c == 1 or d == 1:
  print(0)
  exit()
if a%c < b%c and a%c == 0 and b%c != c-1:
  xc = (b-a+1)//c + 1
elif a%c < b%c:
  xc = (b-a+1)//c
elif a%c > b%c and b%c == 0 and a%c == 1:
  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 and a%d == 0 and b%d != d-1:
  xd = (b-a+1)//d +1
elif a%d < b%d:
  xd = (b-a+1)//d
elif a%d > b%d and b%d == 0 and a%d == 1:
  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 and a%m == 0 and b%m != m-1:
  xm = (b-a+1)//m +1
elif a%m < b%m:
  xm = (b-a+1)//m
elif a%m > b%m and b%m == 0 and a%m == 1:
  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:
import math

line = input().split()

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

count = 0

ran = b-a+1
c_c = math.floor(ran/c)
d_c = math.floor(ran/d)
cd_c = math.floor(ran/(c*d))
rang = c_c+d_c-cd_c
result_c = ran - rang
  

print(result_c)

Submission status: Wrong Answer

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

import math

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

E = C*D/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: 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)
lcm=c*d/g
Ncd=int(b/(lcm))-int((a-1)/(lcm))
Nc=int(b/c)-int((a-1)/c)
Nd=int(b/d)-int((a-1)/d)
print(b-a+1-(Nc+Nd-Ncd))

Submission status: Wrong Answer

Solution code:
s = input().split()
count=0
n = int(s[2])*int(s[3])
for i in range(int(s[0]),int(s[1])+1):
    if i%n!=0:
        count+=1
        
print(count)

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
 
gcd = fractions.gcd(c,d)
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)-int((b_cd-a_cd)))
print(int(ans))

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
if a==b:
  if a%c!=0 and a%d!=0:
    print(1)
  else:
    print(0)
elif c==1 or d==1:
  print(0)
else:
  cd = int(c*d/fractions.gcd(c, d))
  waru_c = int(b/c)-int((a-1)/c)
  waru_d = int(b/d)-int((a-1)/d)
  waru_cd = int(b/cd)-int((a-1)/cd)
  print((b-a+1)-(waru_c+waru_d-waru_cd))

Submission status: Wrong Answer

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

figs = b-a + 1

if a % c == 0:
    minlenc = a//c -1
else:
    minlenc = a//c
maxlenc = b//c 

if a % d == 0:
    minlend = a//d -1
else:
    minlend = a//d
maxlend = b//d 

if a % (c*d) == 0:
    minlencd = a//(c*d) -1
else:
    minlencd = a//(c*d)
maxlencd = b//(c*d)


allfigs = []

clen = maxlenc - minlenc
dlen = maxlend - minlend
cdlen = maxlencd - minlencd


#for i in range(minlenc , maxlenc):
#    clen += 1
#for i in range(minlend , maxlend):
#    dlen += 1
#for i in range(minlencd , maxlencd):
#    cdlen += 1


figs = figs + cdlen - clen -dlen


#for i in range(a,b+1):
#    if i % c == 0:
#        continue
#    elif i % d == 0:
#        continue
#    else:
#        figs += 1

print(figs)


#print(figs)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(x, y):
    return (x * y) // 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: Wrong Answer

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

if c == 1 or d == 1:
    print(0)
    exit()

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

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

e = lcm(c, d)

if a % c != 0:
    c1 = (a // c + 1) * c
else:
    c1 = a
if b % c != 0:
    c2 = (b // c) * c
else:
    c2 = b
cCount = (c2 - c1) // c + 1

dCount = 0
if c != d:
    if a % d != 0:
        d1 = (a // d + 1) * d
    else:
        d1 = a
    if b % d != 0:
        d2 = (b // d) * d
    else:
        d2 = b
    dCount = (d2 - d1) // d + 1

eCount = 0
if e != c and e <= b:
    if a % e != 0:
        e1 = (a // e + 1) * e
    else:
        e1 = a
    if b % d != 0:
        e2 = (b // e) * e
    else:
        e2 = e
    eCount = (e2 - e1) // e + 1

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

Submission status: Wrong Answer

Solution code:
def gcd(m, n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x %y != 0:
            z = x % y
            x = y
            y = z
        else:
            return z
def lcm(x, y):
    return int((x * y) / gcd(x, y))
a,b,c,d = map(int,input().split())
count = 0
if c == 1 or d == 1:
    print(0)
else:
    lcm = lcm(c,d)
    ans1 = (b // c - a // c + b // d - a // d - b // lcm + a // lcm)
    print(b - a + 1 - ans1)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int, input().split())
A -= 1
if C % 2 == 0 and D % 2 == 0:
    X = B//(C*D//2) - A//(C*D//2)
else:
    X = B//(C*D) - A//(C*D)
cc = B//C - A//C
dd = B//D - A//D
if max(C,D)%min(C,D) == 0:
    X += min(cc,dd)
if A+1==B==C or A+1==B==D:
    print(0)
else:
    print(B - A - cc - dd + X)

Submission status: Wrong Answer

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)


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: Wrong Answer

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

A,B,C,D = map(float, input().split())
n = B-A+1
r = floor(B/C) - ceil(A/C) + 1 +\
    floor(B/D) - ceil(A/D) + 1 -\
    (floor(B/lcm(C,D)) - ceil(A/lcm(C,D)) + 1)
print(int(n-r))

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
if c>a:
    x=c
y=a+a%d
if d>a:
    y=d
e=lcm(c,d)
z=a+a%e
if e>a:
    z=e
x2=(b-x)//c+1
if x>b:
    x=0
y2=(b-y)//d+1
if y>b:
    y=0
z2=(b-z)//e+1
if z>b:
    z=0
if c>b and d>b:
    print(b-a+1)
elif d>b:
    print(b-a+1-x2)
elif c>b:
    print(b-a+1-y2)
elif e>b:
    print(b-a-x2-y2+1)
else:
    print(b-a+1-x2-y2+z2)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
# C
def gcd(a,b):
    if a<b: a,b = b,a
    r = a % b
    while(r!=0):
        a,b = b,r
        r = a%b
    return b

def nonDivided(n,s,t):
    if not n > 0:
        return 0
    else:
        return n-int(n/s)-int(n/t)+int(n*gcd(s,t)/(s*t))

if __name__=='__main__':
    A,B,C,D = map(int,input().split())
    print(nonDivided(B,C,D)-nonDivided(A-1,C,D))

Submission status: Wrong Answer

Solution code:
import math
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: Wrong Answer

Solution code:
import numpy as np
import fractions

def main():
    abcd = list(map(int, input().split(' ')))
    al = abcd[1] - abcd[0] + 1
    cc = abcd[1] // abcd[2] - (abcd[0]-1) // abcd[2]
    dd = abcd[1] // abcd[3] - (abcd[0]-1) // abcd[3]
    skbs = (abcd[2] * abcd[3]) // fractions.gcd(abcd[2], abcd[3])
    dis = cc + dd - (abcd[1] // skbs - abcd[0] // skbs)
    print(int(al - dis))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int,input().split())
cc=math.floor(b/c)-math.ceil(a/c)
dd=math.floor(b/d)-math.ceil(a/d)
cd=0
#cd=math.floor(b/(c*d/math.gcd(c, d)))-math.ceil(a/(c*d/math.gcd(c, d)))
print(b-a-cc-dd+cd)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):

    while b:

        a, b = b, a % b

    return a

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

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

#print(X,Y)

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: Wrong Answer

Solution code:
import numpy as np
import fractions

def main():
    abcd = list(map(int, input().split(' ')))
    al = abcd[1] - abcd[0] + 1
    cc = abcd[1] // abcd[2] - (abcd[0]-1) // abcd[2]
    dd = abcd[1] // abcd[3] - (abcd[0]-1) // abcd[3]
    print(cc, dd)
    skbs = (abcd[2] * abcd[3]) // fractions.gcd(abcd[2], abcd[3])
    dis = cc + dd - (abcd[1] // skbs - abcd[0] // skbs)
    print(int(al - dis))

if __name__ == "__main__":
    main()

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

# 範囲内の最も小さい数値
def cnt(inp):
  min_ = inp * (int((A-1) / inp) + 1)
  max_ = inp * (int((B) / inp))
  num = (max_ - min_) / inp + 1
#  return([min_,max_,int(num)])
  return(int(num))

Ccnt = cnt(C)
Dcnt = cnt(D)
lcm = C*D // gcd(C,D)
CDcnt = cnt(lcm)

# print(Ccnt, Dcnt, CDcnt,(B+1-A)-Ccnt[2]-Dcnt[2]+CDcnt[2])
print((B+1-A)-Ccnt-Dcnt+CDcnt)

Submission status: Wrong Answer

Solution code:
import math
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 = 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: 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 = map(int,input().split())

bandc = b // c 
bandd = b // d
bandcd = b // lcm(c,d)

aandc = a // c 
aandd = a // d
aandcd = a // lcm(c,d)

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

Submission status: Wrong Answer

Solution code:
# 2019/06/22
# AtCoder Beginner Contest 131 - C

import fractions
# Least Common Multiple
def lcm_fgf(a, b):
    return int(a * b / fractions.gcd(a, b))

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

clist = list()
dlist = list()
cdlist = list()

cd = lcm_fgf(c, d)

# wkc = (a // c) * c
# wkd = (a // d) * d
# wkcd = (a // cd) * cd

wkccnt = (b - a + 1) // c
wkdcnt = (b - a + 1) // d
wkcdcnt = (b - a + 1) // cd
rem1 = (b - a + 1) % c
rem2 = (b - a + 1) % d

candiv = wkccnt + wkdcnt - wkcdcnt
ans = (b - a + 1) - candiv

if rem2 > 0:
    ans -= 1

# Output
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

if A > B :
    print(0)
else :
    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 / fractions.gcd(C,D))

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

    print(ans)

Submission status: Wrong Answer

Solution code:
#問題
import sys

input=sys.stdin.readline()
a,b,c,d=map(int,input.split())
if c>d:
    m=c
    n=d
else:
    m=d
    n=c
while True:
    t=m%n
    if t==0:
        break
    else:
        m=n
        n=t
cd=c*d/n
ans_1=int(b/c)-int((a-1)/c)
ans_2=int(b/d)-int((a-1)/d)
ans_3=int(b/cd)-int((a-1)/cd)
if c==1 or d==1:
    print(0)
else:
    print(b-a+1-ans_1-ans_2+ans_3)

Submission status: Wrong Answer

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

cc=math.floor(b/c)-math.ceil(a/c)+1
dd=math.floor(b/d)-math.ceil(a/d)+1
cd=math.floor(b/(lcm(c, d)))-math.ceil(a/(lcm(c, d)))+1

print(b-a+1-(cc+dd-cd))

Submission status: Wrong Answer

Solution code:
#coding:utf-8
a, b, c, d = map(int, input().split())

# cで割り切れる個数を求める
c_div = abs((b // c) - ((a - 1) // c))
print(c_div)

# dで割り切れる個数を求める
d_div = abs((b // d) - ((a - 1) // d))
print(d_div)

# cとd両方で割り切れる数を求める
cd = c * d
cd_div = abs((b // cd) - ((a - 1)// cd))
print(cd_div)

div =  c_div  + d_div - cd_div

print((b-a+1)-div)

Submission status: Wrong Answer

Solution code:
import fractions

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

def lcm(x, y):
    return int((x * y) / fractions.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: Wrong Answer

Solution code:
import math
import fractions

def main():

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

    CD = C * D / fractions.gcd(C,D)
    #print("CD = ", CD)

    count_C = (B//C - (A-1)//C)
    #print("count_C = ", count_C)

    count_D = (B//D - (A-1)//D)
    #print("count_D = ", count_D)

    count_CD = (B//CD - (A-1)//CD)
    #print("count_CD = ", count_CD)

    print(int(B-A+1 - (count_C + count_D - count_CD)))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a, b, c ,d = map(int, 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)
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: Wrong Answer

Solution code:
import math
import fractions


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


if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    warikireru_c = math.floor(b / c) - math.ceil(a / c) + 1
    warikireru_d = math.floor(b / d) - math.ceil(a / d) + 1
    lcm_1 = lcm(c, d)
    warikireru_lcm = math.floor(b / lcm_1) - math.ceil(a / lcm_1) + 1
    num = b - a + 1
    print(num - (warikireru_c + warikireru_d - warikireru_lcm))

Submission status: Wrong Answer

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

cntC = int(B / C) - int(A / C)
cntD = int(B / D) - int(A / D)

if A % C == 0:
    cntC += 1

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

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


CD = lcm(C, D)

cntCD = int(B / CD) - int(A / CD)

# print(cntC, cntD, cntCD, CD)
calc = (B-A+1) - (cntC + cntD - cntCD)

print(calc)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, 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)


ac = int(A / C)
bc = int(B / C)
ad = int(A / D)
bd = int(B / D)
acd = int(A / lcm(C, D))
bcd = int(B / lcm(C, D))

if A % C == 0:
    c_div = bc - ac + 1
else:
    c_div = bc - ac
if A % D == 0:
    d_div = bd - ad + 1
else:
    d_div = bd - ad
if B % lcm(C, D) == 0:
    cd_div = bcd - acd + 1
else:
    cd_div = bcd - acd

print(B - A + 1 - c_div - d_div + cd_div)

Submission status: Wrong Answer

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

if c == 1 or d == 1:
    print(0)
    exit()

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

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

e = lcm(c, d)

if a % c != 0:
    c1 = (a // c + 1) * c
else:
    c1 = a
if b % c != 0:
    c2 = (b // c) * c
else:
    c2 = b
cCount = (c2 - c1) // c + 1

dCount = 0
if c != d:
    if a % d != 0:
        d1 = (a // d + 1) * d
    else:
        d1 = a
    if b % d != 0:
        d2 = (b // d) * d
    else:
        d2 = b
    dCount = (d2 - d1) // d + 1

eCount = 0
if e != c:
    if a % e != 0:
        e1 = (a // e + 1) * e
    else:
        e1 = a
    if b % d != 0:
        e2 = (b // e) * e
    else:
        e2 = e
    eCount = (e2 - e1) // e + 1

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions

input=stdin.readline().rstrip().split()
A=int(input[0])
B=int(input[1])
C=int(input[2])
D=int(input[3])

output=0
Cmax=int(B/C)
Cmin=int((A-1)/C)
Dmax=int(B/D)
Dmin=int((A-1)/D)
CD=C*D/fractions.gcd(C,D)
CDmax=int(B/CD)
CDmin=int((A-1)/CD)
output=(B-A+1)-((Cmax-Cmin)+(Dmax-Dmin)-(CDmax-CDmin))
#print(Cmax,Cmin,Dmax,Dmin,CDmax,CDmin)
print(output)

Submission status: Wrong Answer

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

a, b, c, d = map(int, input().split())
num = 0
cd = c*d/(gcd(c,d))
s = b - a + 1
s_c = int(s/c)
s_d = int(s/d)
s_cd = int(s/cd)
if(a%c > b%c):
  num = num + 1
if(a%d > b%d):
  num = num + 1
if(a%cd > b%cd):
  num = num - 1
print(s -(s_c + s_d - s_cd) - num)

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

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

def n_division(begin, end, divisor):
	min_divisor = None
	max_divisor = None
	for i in range(begin, min(end+1, begin+divisor)):
		# print(i)
		if i % divisor == 0:
			min_divisor = i
	for i in range(end, max(begin-1, end-divisor), -1):
		# print(i)
		if i % divisor == 0:
			max_divisor = i
			
	if min_divisor is None:
		return 0
	else:
		return (max_divisor - min_divisor) / divisor + 1 
		
# print(f'a: {a}, b: {b}, div_c: {n_division(a, b, c)}, div_d: {n_division(a, b, d)}')
# print(f'div_cd: {n_division(a, b, c*d)}')
		
res = b - a + 1 -(n_division(a, b, c) + n_division(a, b, d) - n_division(a, b, c*d))
print(int(res))

Submission status: Wrong Answer

Solution code:
import math
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 = 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: Wrong Answer

Solution code:
print(0)