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:
from fractions import gcd

def main():
    a,b,c,d = map(int,input().split(" "))
    n = b - a + 1
    cd = int(c * d / gcd(c, d))
    noinclude = int((a-1)/c) + int((a-1)/d) - int((a-1)/cd)
    include = int(b/c) + int(b/d) - int(b/cd) - noinclude
    if c == 1 or d == 1:
        include = n
    print(n - include)

if __name__ == '__main__':
    main()

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=int(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:
# 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 *
import fractions
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())

a, b, c, d = readmi()

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

parents = list(map(int,input().split(' ')))
All = parents[1] - parents[0]
min_2 = (parents[2]*parents[3]) // fractions.gcd(parents[2], parents[3])

All = All-All//parents[2]-All//parents[3]+All//min_2
if parents[2]>=parents[0] and parents[2]<=parents[1]:
    All = All-1
if parents[3]>=parents[0] and parents[3]<=parents[1]:
    All = All-1

print(All)

Submission status: Wrong Answer

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


#[1,x]のうちCで割り切れる
def C(x):
    return x // c


#Dで割り切れる
def D(x):
    return x // d


#C*Dで割り切れる
def CD(x):
    return x // (c * d)


#CまたはDで割り切れる
def CorD(x):
    return C(x) + D(x) - CD(x)


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

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
rem = b - a + 1
pattern1 = (rem + a % c - 1)//c + (a % c == 0 and a % c == 0)
pattern2 = (rem + a % d - 1)//d + (a % d == 0 and a % d == 0)
bi = (c * d // fractions.gcd(c, d))
pattern3 = (rem + a % bi - 1)//bi + (a % bi == 0 and b % bi == 0)
print(rem - pattern1 - pattern2 + pattern3)

Submission status: Wrong Answer

Solution code:
import math
A, B, C, D = map(int, input().split())
N = B - A + 1  #整数列の長さ

tmp = 0   #最後にNから引く
mod = A % C
tmp += math.ceil((N-mod)/C)
mod = A % D
tmp += math.ceil((N-mod)/D)
mod = A % (D*C)
tmp -= math.ceil((N-mod)/(D*C))

print(N-tmp)

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 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)
if e>b:
    print(b-a-x2-y2+1)
else:
    print(b-a+1-x2-y2+z2)

Submission status: Wrong Answer

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

cx=math.ceil(A/C)
cy=math.floor(B/C)
dx=math.ceil(A/D)
dy=math.floor(B/D)



ex=math.ceil(A/(C*D))
ey=math.floor(B/(C*D))


if cy<cx:
    cy=cx
if dy<dx:
    dy=dx
if ey<ex:
    ey=ex



print("{}".format(B-A+1-(cy-cx+1)-(dy-dx+1)+(ey-ex+1)))

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

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


l = raw_input().split()
a = int(l[0])
b = int(l[1])
c = int(l[2])
d = int(l[3])
lcm = ((c*d)//(gcd(c,d)))

test = []
test.append((a-1)/c)
test.append((a-1)/d)

test.append(b/c)
test.append(b/d)

test.append(a/lcm)
test.append(b/lcm)

ans = ( (test[2]-test[0]) + (test[3]-test[1]) )- (test[5]-test[4])

ans = (b-a+1) - ans

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
if sais_mx > 0:
    sais_count = sais_mx + sais_mm
else:
    sais_count = 0

# print('sais_mx ' + str(sais_mx))
# print('sais_count ' + str(sais_count))

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())
x = abs(A-B)//C + 1
y = abs(A-B)//D + 1
if B//((C*D)//fractions.gcd(C,D)) - A//(((C*D)//fractions.gcd(C,D))) == 0:
    z = 0
else:
    z = abs(A-B)//((C*D)//fractions.gcd(C,D)) + 1
print(B-A+1-x-y+z)

Submission status: Wrong Answer

Solution code:
a,b,c,d = list(map(int,input().split()))
ans = 0
if b % c == 0:
    ans += int(b/c)
else:
    ans += int((b- (b%c)) /c)

if (a-1) % c == 0:
    ans -= (a-1)/c
else:
    ans -= ((a-1)- ((a-1)%c)) /c

ans = int(ans)
if b % d == 0:
    ans += b/d
else:
    ans += (b- (b%d)) /d

if (a-1) % d == 0:
    ans -= (a-1)/d
else:
    ans -= ((a-1)- ((a-1)%d)) /d
ans = int(ans)
e = c*d

c_2 = c
d_2 = d
if (c_2< d_2):
    tmp = c_2
    c_2 = d_2
    d_2 = tmp
r = c_2 % d_2
while r != 0:
    c_2 = d_2
    d_2 = r
    r = c_2 % d_2
e = int(e /d_2)

ans2 = 0


if b % e == 0:
    ans2 += b/e
else:
    ans2 += (b- (b%e)) /e
if (a-1) % e == 0:
    ans2 -= (a-1)/e
else:
    ans2 -= ((a-1)- ((a-1)%e)) /e

sa = ans - ans2
print(int(b-a+1-sa))

Submission status: Wrong Answer

Solution code:
import math
import fractions


def lcm(x, y):
    return (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:
import math


def gcd(m, n):
    while n:
        m, n = n, m % n
    return m


A, B, C, D = map(int, input().split())  # A以上B以下の整数のうち、CでもDでも割り切れないものの個数

CD_lcm = (C * D) / gcd(C, D)

# B以下の全ての数でCで割れるものの個数hoge
hogeBC = math.floor(B / C)
# A-1以下の全ての数でCで割れるものの個数fuga
fugaA1C = math.floor((A-1) / C)

# B以下の全ての数でDで割れるものの個数
piyoBD = math.floor(B / D)
# A-1以下の全ての数でDで割れるものの個数
toriA1D = math.floor((A-1) / D)

# B以下の全ての数でCとDの最小公倍数で割れるもの
yoshiBCD = math.floor(B / (CD_lcm))
# A-1以下の全ての数でCとDの最小公倍数で割れるもの
takaA1CD = math.floor((A-1) / (CD_lcm))

# A以上B以下の整数でCで割り切れるものの個数
Ccan = hogeBC-fugaA1C
# A以上B以下の整数でDで割り切れるものの個数
Dcan = piyoBD - toriA1D
# A以上B以下の整数でCでもDでも割り切れるものの個数
CDcan = yoshiBCD - takaA1CD


# CでもDでも割り切れるものの個数
count = Ccan + Dcan - CDcan
print(B-A+1 - count)

Submission status: Wrong Answer

Solution code:
import fractions

def antidiv(x,l,c,d):
    if x == l or x < 0:
        return l - (l // c) - (l // d) + 1
    else:
        return x - (x // c) - (x // d) 

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

l = (c*d)//fractions.gcd(c,d)


aq = a // l
ar = a % l
bq = b // l
br = b % l
#print(br)

qq = bq - aq - 1
r1 = antidiv(l,l,c,d) - antidiv(ar-1,l,c,d)
r2 = antidiv(br,l,c,d)

if a!=b:
    ans = qq * antidiv(l,l,c,d) + r1 + r2
elif a % c != 0 and a % d != 0:
    ans = 1
else:
    ans = 0


print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import fractions
import math


#from numba import jit
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


def resolve():
    A, B, C, D = map(int, input().split())
    size = B - A + 1
    C_warikire = math.ceil(size / C)
    D_warikire = math.ceil(size / D)
    C_and_D_warikire = math.ceil(size / (lcm(C, D)))
    print(size - C_warikire - D_warikire + C_and_D_warikire)
resolve()

Submission status: Wrong Answer

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

c_offset = (A-1) // C 
c_ = B // C
c = c_ - c_offset

d_offset = (A-1) // D
d_ = B // D
d = d_- d_offset

cd_offset = (A-1) // (D*C)
cd_ = B // (D*C)
cd = cd_- cd_offset

count = B - A - (c + d - cd) +1

print(count)

Submission status: Wrong Answer

Solution code:
import fractions
import math

A,B,C,D = map(int,input().split())
lcm = C*D/fractions.gcd(C,D)
def c_in_a2b(c):
    return (math.ceil(B/c) - math.floor(A/c) + 1)
print(int((B-A+1)- c_in_a2b(C)-c_in_a2b(D)+c_in_a2b(lcm)))

Submission status: Wrong Answer

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

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

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

bb = b-int(b/c)-int(b/d)+int(b/lcm(c,d))   
aa = (a-1)-int((a-1)/c)-int((a-1)/d)+int((a-1)/lcm(c,d))
print(bb-aa)

Submission status: Wrong Answer

Solution code:
import fractions
A, B, C, D = (int(x) for x in input().split())
x = (B // C) - (A // C)
x += (B // D) - (A // D)
lcm = (C * D) // fractions.gcd(C, D)
x -= (B // lcm) - (A // lcm)
print((B - A + 1) - x)

Submission status: Wrong Answer

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

ans=0
gc=int(c*d/gcd(c,d))

if a%c==0:
    ans-=1
if a%d==0:
    ans-=1
if a%gc==0:
    ans+=1

ans+=(b-a+1)-(int(b/c)+int(b/d)-int(a/c)-int(a/d)-int(b/gc)+int(a/gc))

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D =  map(int,input().split(" "))
NUM = B
NUM -= int(B / C)
NUM -= int(B / D)
NUM += int(B / ((C*D)//fractions.gcd(C,D)))
#print(NUM)
LNUM = A-1
LNUM -= int((A-1) / C)
LNUM -= int((A-1) / D)
LNUM -= int((A-1) / (C*D))
#print(LNUM)
print(NUM - LNUM)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor
from fractions import gcd

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

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

ans = B-A+1
ans -= floor(B/C) - ceil(A/C) + 1
ans -= floor(B/D) - ceil(A/D) + 1
ans += floor(B/lcm(C,D)) - ceil(A/lcm(C,D)) + 1

print(ans)

Submission status: Wrong Answer

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


l = raw_input().split()
a = int(l[0])
b = int(l[1])
c = int(l[2])
d = int(l[3])
lcm = ((c*d)//(gcd(c,d)))

test = []
test.append((a-1)/c)
test.append((a-1)/d)

test.append(b/c)
test.append(b/d)

test.append(a/lcm)
test.append(b/lcm)

print test

ans = ( (test[2]-test[0]) + (test[3]-test[1]) )- (test[5]-test[4])

ans = (b-a+1) - ans

print ans

Submission status: Wrong Answer

Solution code:
def u(a,b):
  if b == 0:
    return a
  return u(b, a%b)

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

e=c*d/u(c,d)
ac = (a - 1) // c
bc = b // c
ad = (a - 1) // d
bd = b // d
ae = int((a - 1) // e)
be = int(b // e)

print(b - (a -1) - (bc - ac + bd - ad ) + (be - ae))

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
rem = b - a + 1
pattern1 = (rem + a % c - 1)//c + (a % c == 0 and a % c == 0)
pattern2 = (rem + a % d - 1)//d + (a % d == 0 and a % d == 0)
bi = c*d
pattern3 = (rem + a % bi - 1)//bi + (a % bi == 0 and b % bi == 0)
print(rem - pattern1 - pattern2 + pattern3)

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

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

_c = c
_d = d
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) or (b%c != 0 and b%d != 0)) : ans +=1

print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
#sum=0
"""
for i in range(A,B+1):
    #if(i%C!=0 and i%D!=0):
    if(i%C!=0):
        if(i%D!=0):
            sum+=1
"""
sum1=(A-1)//C
sum2=B//C
sum3=sum2-sum1
sum1=(A-1)//D
sum2=B//D
sum4=sum2-sum1
sum1=(A-1)//(D*C)
sum2=B//(D*C)
sum5=sum2-sum1
sum=sum3+sum4-sum5
sum=B-A+1-sum


print(sum)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
def gcd(a,b):
  x=max(a,b)
  y=min(a,b)
  if(x%y)==0:
    return y
  else:
    while x%y!=0:
      z=x%y
      x=y
      y=z
    else:
      return z
n=input().rstrip().split(" ")
for i in range(4):
    n[i]=int(n[i])
toc=(n[0]%n[2])
tod=(n[0]%n[3])
tocd=(n[0]%(n[2]*n[3]//gcd(n[2],n[3])))
#print(toc)
#print(tod)
#print(tocd)
d=n[1]-n[0]+1
ans=[d-((d+toc)//n[2]),d-((d+tod)//n[3]),d-((d+tocd)//(n[2]*n[3]//gcd(n[2],n[3])))]
#print(ans)
print(ans[0]+ans[1]-ans[2])

Submission status: Wrong Answer

Solution code:
from math import ceil
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 = (ceil(a/c)*c)-1
r = (b//c)*c
k1 = (r-l)//c+1

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

w = lmc(c, d)
l = (ceil(a/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):
    r = a % b
    while (r != 0):
        a = b
        b = r
        r = a % b
    return b

def c(begin, end, num):
    r = end - begin + 1
    if r < num:
        if begin < num < end:
            return 1
        else:
            return 0
    if num == r:
        return 1
    if num < r:
        begin = ((begin // num) + 1) * num
        r = end - begin + 1
        ans = 1 + (r // num)
        return ans

A, B, C, D = [int(x) for x in input().split(' ')]
C, D = (C, D) if C < D else (D, C)
CD = (C * D) // gcd(C, D)

count = 0

if A == B:
    if A % C == 0 or A % D == 0:
        print(0)
    else:
        print(1)
    exit(0)
else:
    if C == D:
        c_count = c(A, B, C)
        count = c_count
    elif D == CD:
        c_count = c(A, B, C)
        d_count = c(A, B, D)
        count = c_count + d_count
    else:
        c_count = c(A, B, C)
        d_count = c(A, B, D)
        cd_count = c(A, B, CD)
        count = c_count + d_count - cd_count

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

Submission status: Wrong Answer

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

# n_c = 0
# n_d = 0
# n_cd = 0
# for i in range(A,B+1):
#     if(i % C == 0):
#         n_c = i // C
#     n_d = i // D
#     n_cd = i//(C*D)

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

n_c = B//C - A//C
n_d = B//D - A//D
CD = lcm(C,D)
n_cd = B//(CD) - A//(CD)

if(A%C == 0):
    n_c += 1
if(A%D==0):
    n_d += 1
if(A%CD==0):
    n_cd += 1


if (max(C,D)%min(C,D) == 0):
    ans = (B-A+1) - max(n_c, n_d)
else:
    ans = (B-A + 1) - (n_c + n_d - n_cd)

# print(n_c)
# print(n_d)
# print(n_cd)

print(ans)




if (max(C,D)%min(C,D) == 0):
    ans = (B-A+1) - max(n_c, n_d)
else:
    ans = (B-A + 1) - (n_c + n_d - n_cd)

# print(n_c)
# print(n_d)
# print(n_cd)

print(ans)

Submission status: Wrong Answer

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

if A == B and A!=C and A!=D:
    print(1)
    exit()


cCnt = (B-A)//C
dCnt = (B-A)//D
cdCnt = (B-A)//(C*D)

print(B - A - cCnt - dCnt + cdCnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int,input().split())
if int(b/c)!=int(a/c):
    if a%c==0:
        cc=int(b/c)-int(a/c)
    else:
        cc = int(b / c) - (int(a / c)+1)
else:
    cc=int(b/c)

if int(b / d) != int(a / d):
    if a%d==0:
        dd = int(b / d) - int(a / d)
    else:
        dd=int(b/d)-int((a/d)+1)
else:
    dd=int(b / d)
i=0
f=[c]
x=10000000
k=[c,d]

while x!=0:
    x=max(k)%min(k)

    if x!=0:
        f.append(x)
    k.sort()
    k[1]=x
#Wprint(min(f))

if (int(b / (c*d/min(f))))!= (int(a / (c*d/min(f)))):
    if a%d==0:
        cd = int(b / (c*d/min(f)))- int(a / (c*d/min(f)))
    else:
        cd=int(b/(c*d/min(f)))-(int(a/(c*d/min(f)))+1)
else:
    cd=int(b/(c*d/min(f)))


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

Submission status: Wrong Answer

Solution code:
x = input()
x = str(x).split(" ")

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

n = b-a

print( n - int(n/d) - int(n/c) + int(n/(d*c)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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 (x * y) // gcd(x, y)
a,b,c,d = map(int,input().split())
count = 0
lcm = lcm(c,d)
ans1 = (b // c - a // c + b // d - a // d - b // lcm + a // lcm)
print(b - a - ans1 + 1)

Submission status: Wrong Answer

Solution code:

import fractions

A,B,C,D = map(int, input().split())
ans=B-A+1


E=D * C // fractions.gcd(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
nc=(nC_final-nC_initial+1)
nd=(nD_final-nD_initial+1)
ne=(nE_final-nE_initial+1)
if B<C:
    nc=0
    nE=0
if B<D:
    nd=0
    nE=0
#print(ans,nC_initial,nC_final,nD_initial,nD_final, nE_initial,nE_final)
#print(ans,nc,nd,ne)
print(ans-nc-nd+ne)

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")
elif c>b and d>b:
    print("f")
elif d>b:
    print("f")
elif c>b:
    print("f")
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 = 0

c_n_min = math.ceil(A / C)
c_n_max = math.floor(B / C)
if (C <= B):
    c_n = c_n_max - c_n_min + 1
else:
    c_n = 0

d_n_min = math.ceil(A / D)
d_n_max = math.floor(B / D)
if (D <= B):
    d_n = d_n_max - d_n_min + 1
else:
    d_n =0

cd = C * D // fractions.gcd(C,D)
cd_n_min = math.ceil(A / cd)
cd_n_max = math.floor(B / cd)

if (cd <= B):
    cd_n = cd_n_max - cd_n_min + 1
else:
    cd_n = 0

ans = (B - A + 1) - (c_n + d_n - cd_n)
print(ans)

Submission status: Wrong Answer

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

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

cd = lcm(c, d)

# cの倍数とdの倍数の個数を数える
# cの倍数dの倍数の個数を引く
ca = ((a-1) // c)
print(ca)
cb = (b // c)
print(cb)
tmp_c = cb - ca

da = (a // d)
print(da)
db = (b // d)
print(db)
tmp_d = db - da

cda = (a // cd)
print(cda)
cdb = (b // cd)
print(cdb)
tmp_cd = cdb - cda
ans = b - a + 1 - (tmp_c + tmp_d - tmp_cd)

print(ans)

Submission status: Wrong Answer

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

c_offset = (A-1) // C 
c_ = B // C
c = c_ - c_offset

d_offset = (A-1) // D
d_ = B // D
d = d_- d_offset

cd_offset = (A-1) // (D*C)
cd_ = B // (D*C)
cd = cd_- cd_offset

print(c)
print(d)
print(cd)

count = B - A - (c + d - cd) +1

print(count)

Submission status: Wrong Answer

Solution code:
import fractions
import math

A,B,C,D = map(int,input().split())
lcm = C*D/fractions.gcd(C,D)
def c_in_a2b(c):
    return (math.ceil(B//c) - math.floor(A//c) + 1)
print(int((B-A+1)- c_in_a2b(C)-c_in_a2b(D)+c_in_a2b(lcm)))

Submission status: Wrong Answer

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

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

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

cd=b//c-(a-1)//c
dd=b//d-(a-1)//d
cdd=b//(cdlcm)-(a-1)//(cdlcm)

print(round(b-a+1-(cd+dd-cdd)))

Submission status: Wrong Answer

Solution code:
a = list(map(int,input().split()))
B = a[0]
A = a[1]
C = a[2]
D = a[3]
ANS_1 = A - A//C - A//D +  A//(C*D)
E = B-1
ANS_2 = E - E//C - E//D +  E//(C*D)
print(ANS_1 - ANS_2)

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)
	if A == B:
		if A % C == 0 or A % D == 0:
			print(0)
			sys.exit()
		else:
			print(1)
			sys.exit()

	if C == D or C % D == 0 or D % C == 0:
		tmp_C2 = B // C
		tmp_C2ama = B % C

		tmp_C1 = A // C
		tmp_C1ama = A % C

		tmp = (tmp_C2-tmp_C1)

		tmp2 = 0
		if tmp_C1ama == 0:
			tmp2 -=1

		ans = B-A-tmp+1+tmp2
		print(ans)
		sys.exit()

	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

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

	tmp2 = 0
	if tmp_C1ama == 0:
		tmp2 -=1
	if tmp_D1ama == 0:
		tmp2 -=1

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

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

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

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:
#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)

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

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

cnt = B - bc - bd + bcd - (A-1) + ac + ad - acd
print(cnt)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

def f(x, c, d):
    return max(x-int(x/c)-int(x/d)+int(x/lcm(c,d)), 0)

A,B,C,D = list(map(int, input().split()))
print(f(B, C, D)-f(A-1, C, D))

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 = int(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=list(map(int,input().split()))
l_c = int((A+C-1)/C)
u_c = B//C
n_c = u_c - l_c + 1 
l_d = int((A+D-1)/D)
u_d = B//D
n_d = u_d - l_d + 1
CD = C*D
l_cd = int((A+CD-1)/CD)
u_cd = B//CD
n_cd = u_cd - l_cd + 1

n_u = B-A+1
print(n_u-(n_c + n_d - n_cd))

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd
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 // 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:
import numpy as np
a = input()
a, b, c, d = [int(i) for i in a.split(" ")]
count = 0
for i in range(a, b):
	if i % c == 0 and i % d == 0:
		count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import fractions

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

def custom_round(number, ndigits=0):
    if type(number) == int:
        return number
    d_point = len(str(number).split('.')[1])
    if ndigits >= d_point:
        return number
    c = (10 ** d_point) * 2
    return round((number * c + 1) / c, ndigits)

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

x =int((b/c)-(a/c))
y =int((b/d)-(a/d))
n =lcm(c,d)
xy=int((b/n)-(a/n))

ans = (b-a+1) - (x+y-xy)
print(int(ans)-1)

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):
  if a >= b:
    return a*b//gcd(a,b)
  else:
    return a*b//gcd(b,a)


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

k1 = math.ceil(A / C)
k2 = B // C
k3 = math.ceil(A / D)
k4 = B // D

k5 = k2 - k1 + 1
k6 = k4 - k3 + 1

lcm_num = lcm(C, D)
k7 = math.ceil(A / lcm_num)
k8 = B // lcm_num

k9 = k8 - k7 + 1

print(B - A + 1 - k5 - k6 + k9)

Submission status: Wrong Answer

Solution code:
import fractions
list = list(map(int,input().split()))
x = (list[2] * list[3]) // fractions.gcd(list[2], list[3])
p = list[0]//list[2]
q = list[1]//list[2]
r = list[0]//list[3]
s = list[1]//list[3]
t = list[0]//x
u = list[1]//x
l = list[1]-list[0]+1
print(l+p-q+r-s-t+u)

Submission status: Wrong Answer

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

def wareruzu(x):
    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))

Submission status: Wrong Answer

Solution code:
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654

import math
import sys
import itertools
import queue
from functools import reduce
from fractions import gcd

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

mod = 1000000007

if __name__ == "__main__":
    A, B, C, D = map(int, sys.stdin.readline().split())
    A = A - 1
    c_div = int(B // C)
    d_div = int(B // D)
    cd_div = int(B // lcm(C, D))

    not_div1 = B - (c_div + d_div -cd_div)

    c_div = int(A // C)
    d_div = int(A // D)
    cd_div = int(A // lcm(C, D))

    not_div2 = A - (c_div + d_div -cd_div)

    print(not_div1 - not_div2)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
def gcd(a,b):
  x=max(a,b)
  y=min(a,b)
  if(x%y)==0:
    return y
  else:
    while x%y!=0:
      z=x%y
      x=y
      y=z
    else:
      return z
n=input().rstrip().split(" ")
for i in range(4):
    n[i]=int(n[i])
toc=(n[0]%n[2])
tod=(n[0]%n[3])
tocd=(n[0]%(n[2]*n[3]/gcd(n[2],n[3])))
#print(toc)
#print(tod)
#print(tocd)
d=n[1]-n[0]+1
ans=[d-((d+toc)//n[2]),d-((d+tod)//n[3]),d-((d+tocd)//((n[2]*n[3]/gcd(n[2],n[3]))))]
#print(ans)
print(ans[0]+ans[1]-ans[2])

Submission status: Wrong Answer

Solution code:
import fractions

def antidiv(x,l,c,d):
    if x == l or x < 0:
        return l - (l // c) - (l // d) + 1
    else:
        return x - (x // c) - (x // d) 

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

l = (c*d)//fractions.gcd(c,d)


aq = a // l
ar = a % l
bq = b // l
br = b % l
#print(br)

qq = bq - aq - 1
r1 = antidiv(l,l,c,d) - antidiv(ar-1,l,c,d)
r2 = antidiv(br,l,c,d)

ans = qq * antidiv(l,l,c,d) + r1 + r2


print(ans)