There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too.

Each shark will grow some number of flowers s_{i}. For i-th shark value s_{i} is random integer equiprobably chosen in range from l_{i} to r_{i}. Wet Shark has it's favourite prime number p, and he really likes it! If for any pair of neighbouring sharks i and j the product s_{i}·s_{j} is divisible by p, then Wet Shark becomes happy and gives 1000 dollars to each of these sharks.

At the end of the day sharks sum all the money Wet Shark granted to them. Find the expectation of this value.


-----Input-----

The first line of the input contains two space-separated integers n and p (3 ≤ n ≤ 100 000, 2 ≤ p ≤ 10^9) — the number of sharks and Wet Shark's favourite prime number. It is guaranteed that p is prime.

The i-th of the following n lines contains information about i-th shark — two space-separated integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 10^9), the range of flowers shark i can produce. Remember that s_{i} is chosen equiprobably among all integers from l_{i} to r_{i}, inclusive.


-----Output-----

Print a single real number — the expected number of dollars that the sharks receive in total. You answer will be considered correct if its absolute or relative error does not exceed 10^{ - 6}. 

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if $\frac{|a - b|}{\operatorname{max}(1, b)} \leq 10^{-6}$.


-----Examples-----
Input
3 2
1 2
420 421
420420 420421

Output
4500.0

Input
3 5
1 4
2 3
11 14

Output
0.0



-----Note-----

A prime number is a positive integer number that is divisible only by 1 and itself. 1 is not considered to be prime.

Consider the first sample. First shark grows some number of flowers from 1 to 2, second sharks grows from 420 to 421 flowers and third from 420420 to 420421. There are eight cases for the quantities of flowers (s_0, s_1, s_2) each shark grows: (1, 420, 420420): note that s_0·s_1 = 420, s_1·s_2 = 176576400, and s_2·s_0 = 420420. For each pair, 1000 dollars will be awarded to each shark. Therefore, each shark will be awarded 2000 dollars, for a total of 6000 dollars. (1, 420, 420421): now, the product s_2·s_0 is not divisible by 2. Therefore, sharks s_0 and s_2 will receive 1000 dollars, while shark s_1 will receive 2000. The total is 4000. (1, 421, 420420): total is 4000  (1, 421, 420421): total is 0.  (2, 420, 420420): total is 6000.  (2, 420, 420421): total is 6000.  (2, 421, 420420): total is 6000. (2, 421, 420421): total is 4000.

The expected value is $\frac{6000 + 4000 + 4000 + 0 + 6000 + 6000 + 6000 + 4000}{8} = 4500$.

In the second sample, no combination of quantities will garner the sharks any money.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Number theory

Combinatorics

Mathematics

Probability


Solutions:
import sys
buffer = input().split(' ')
[n, p] = [int(buffer[i]) for i in range(len(buffer))]
shark = []
for i in range(n):
	buffer = input().split(' ')
	[a, b] = [int(buffer[i]) for i in range(len(buffer))]
	shark.append([int(b / p) - int((a - 1) / p), int(b - a + 1)])
result = 0.0
for i in range(n):
	[a, b] = shark[i]
	[c, d] = shark[(i + 1) % n]
	temp = float(a * d + b * c - a * c) * 2000 / (b * d)
	result += temp
print(result)


from sys import stdin
inp = stdin.readline
(n, p) = map(int, inp().split())

def cnt(l, r):
	return r // p - l // p if l % p else r // p - l // p + 1

def pb(l, r):
	return cnt(l, r) / (r - l + 1)
w = [pb(*map(int, inp().split())) for _ in range(n)]
ans = 0
for i in range(n):
	ans += 2 * w[i] - w[i] * w[(i + 1) % n]
print(ans * 2000)


(n, p) = map(int, input().split())
a = [tuple(map(int, input().split())) for _ in range(n)]

def divCnt(left, right):
	return right // p - (left - 1) // p
prob = [0] * n
for (i, (left, right)) in enumerate(a):
	(nextLeft, nextRight) = a[(i + 1) % n]
	cnt1 = divCnt(left, right)
	cnt2 = divCnt(nextLeft, nextRight)
	sz1 = right - left + 1
	sz2 = nextRight - nextLeft + 1
	good = cnt1 * sz2 + sz1 * cnt2 - cnt1 * cnt2
	prob[i] += good / (sz1 * sz2)
ret = 0
for pr in prob:
	ret += 2000 * pr
print(ret)


def prob(l, r, p):
	d = r - l + 1
	x = d // p
	l2 = l + x * p
	if l2 > r:
		return x / d
	modl = l2 % p
	modr = r % p
	if modl == 0 or modr == 0 or modl > modr:
		x += 1
	return x / d
sLine = input()
sSplit = sLine.split()
n = int(sSplit[0])
p = int(sSplit[1])
v = []
for i in range(n):
	sLine = input()
	sSplit = sLine.split()
	v.append([int(sSplit[0]), int(sSplit[1])])
fSum = 0.0
for i in range(-1, n - 1):
	f = 1 - (1 - prob(v[i][0], v[i][1], p)) * (1 - prob(v[i + 1][0], v[i + 1][1], p))
	fSum += f
print('{0:.6f}'.format(fSum * 2000))


(N, p) = map(int, input().split())
l = [0 for i in range(N + 1)]
r = [0 for i in range(N + 1)]
for i in range(N):
	(lx, rx) = map(int, input().split())
	l[i] = lx
	r[i] = rx
l[N] = l[0]
r[N] = r[0]
a1 = r[0] // p - (l[0] - 1) // p
n1 = r[0] - l[0] + 1
t1 = (n1 - a1) / n1
ans = 0
for i in range(1, N + 1):
	a2 = r[i] // p - (l[i] - 1) // p
	n2 = r[i] - l[i] + 1
	t2 = (n2 - a2) / n2
	ans += 1 - t1 * t2
	t1 = t2
print(2000 * ans)


(n, p) = map(int, input().split())
z = 1
a = []
b = []
for i in range(0, n):
	(x, y) = map(int, input().split())
	a.append(int(y / p) - int((x - 1) / p))
	b.append(y - x + 1)
ans = 0
for i in range(0, n):
	pz = a[(i + 1) % n]
	z = b[(i + 1) % n]
	py = a[i]
	y = b[i]
	px = a[(i - 1 + n) % n]
	x = b[(i - 1 + n) % n]
	ans += (x * z * py * 2000 + px * pz * (y - py) * 2000 + px * (y - py) * (z - pz) * 1000 + pz * (x - px) * (y - py) * 1000) / float(x * y * z)
print(ans)


import math as m
t = 1

def fn(a, p):
	(l, r) = (a[0], a[1])
	(f, g) = (l // p, r // p)
	ans = g - f + (f * p == l)
	return [ans, r - l + 1]
while t:
	t -= 1
	(n, p) = map(int, input().split())
	ranges = []
	for x in range(n):
		a = list(map(int, input().split()))
		d = fn(a, p)
		ranges.append(d)
	ans = 0
	for i in range(n):
		(d1, x) = (ranges[i][0], ranges[i][1])
		if i == n - 1:
			(d2, y) = (ranges[0][0], ranges[0][1])
		else:
			(d2, y) = (ranges[i + 1][0], ranges[i + 1][1])
		ans += d1 / x + d2 / y - d1 * d2 / (x * y)
	print(ans * 2000)


(n, p) = map(int, input().split())
dp = [0.0] * (n + 1)
res = 0
for i in range(n):
	(l, r) = map(int, input().split())
	dp[i] = 1 - (r // p - (l - 1) // p) / (r - l + 1)
for i in range(n):
	res += 1 - dp[i] * dp[(i + 1) % n]
print(res * 2000)


def main():
	from math import fsum
	(n, p) = map(int, input().split())
	l = []
	for _ in range(n):
		(lo, hi) = map(int, input().split())
		l.append((hi // p - (lo - 1) // p) / (hi - lo + 1))
	(x, a) = (0.0, l[-1])
	for b in l:
		x -= a * b
		a = b
	l.append(x * 0.5)
	print(fsum(l) * 4000.0)
main()


(n, p) = list(map(int, input().split()))
flowers = [list(map(int, input().split())) for _ in range(n)]
primes = [r // p - (l - 1) // p for (l, r) in flowers]
ret = 0
for i in range(n):
	j = (i + 1) % n
	total1 = flowers[i][1] - (flowers[i][0] - 1)
	total2 = flowers[j][1] - (flowers[j][0] - 1)
	probnot1 = (total1 - primes[i]) / total1
	probnot2 = (total2 - primes[j]) / total2
	ret += 1 - probnot1 * probnot2
print(ret * 2000)


(n, p) = map(int, input().split(' '))
s = list(map(lambda x: (x[1] // p * p - (x[0] - 1) // p * p) / p / (x[1] - x[0] + 1), [list(map(int, input().split(' '))) for i in range(n)]))
ans = sum([(1 - (1 - s[i]) * (1 - s[i - 1])) * 2000 for i in range(n)])
print(ans)


(num_prime, prime) = input().split()
num_prime = int(num_prime)
prime = int(prime)
probability = []
sum = 0
for i in range(num_prime):
	(lower_temp, upper_temp) = input().split()
	lower_temp = int(lower_temp)
	upper_temp = int(upper_temp)
	probability.append((upper_temp // prime - (lower_temp - 1) // prime) / (upper_temp - lower_temp + 1))
for i in range(num_prime - 1):
	sum += (probability[i] + probability[i + 1] - probability[i] * probability[i + 1]) * 2000
sum += (probability[0] + probability[-1] - probability[0] * probability[-1]) * 2000
print(sum)


import sys
input = sys.stdin.readline

def read_int():
	return int(input().strip())

def read_ints():
	return list(map(int, input().strip().split(' ')))

def count_p(A, B, p):
	return B // p - (A - 1) // p

def solve():
	(n, p) = read_ints()
	lr = []
	for _ in range(n):
		lr.append(read_ints())
	total = 0
	for i in range(n):
		left_p = count_p(lr[i][0], lr[i][1], p)
		j = (i + 1) % n
		right_p = count_p(lr[j][0], lr[j][1], p)
		total += ((lr[i][1] - lr[i][0] + 1) * right_p + (lr[j][1] - lr[j][0] + 1) * left_p - left_p * right_p) / ((lr[i][1] - lr[i][0] + 1) * (lr[j][1] - lr[j][0] + 1))
	return 2000 * total
print(solve())


import math
from fractions import Fraction
(n, p) = [int(x) for x in input().split()]
exp_mean = 0
(first_l, first_r) = (None, None)
(last_good, last_all) = (None, None)
for i in range(n + 1):
	(l, r) = (None, None)
	if i < n:
		(l, r) = [int(x) for x in input().split()]
		if first_l is None:
			(first_l, first_r) = (l, r)
	else:
		(l, r) = (first_l, first_r)
	upper = r // p
	lower = math.ceil(l / p)
	cur_good = upper - lower + 1
	cur_all = r - l + 1
	if last_good is not None:
		cur_mean = float(2000 * (cur_good * last_good + (cur_all - cur_good) * last_good + (last_all - last_good) * cur_good) / (cur_all * last_all))
		exp_mean += cur_mean
	last_good = cur_good
	last_all = cur_all
print(exp_mean)


nextInt = lambda : map(int, input().split())
(n, p) = nextInt()
a = [0] * n
ret = 0
for i in range(n):
	(l, r) = nextInt()
	a[i] = (r // p - (l - 1) // p) / (r - l + 1)
for i in range(n):
	ret += a[i] + a[i - 1] - a[i] * a[i - 1]
ret *= 2000
print(ret)


(n, m) = map(int, input().split())

def f():
	(a, b) = map(int, input().split())
	return (b // m - (a - 1) // m) / (b - a + 1)
a = [f() for _ in range(n)]
r = 0
for i in range(n):
	r += 1 - (1 - a[i]) * (1 - a[(i + 1) % n])
print(r * 2000)


(n, p) = map(int, input().split())

def count_divisors(a, b, p):
	x = b // p
	y = (a - 1) // p
	return x - y
arr = []
for i in range(n):
	(a, b) = map(int, input().split())
	arr.append((count_divisors(a, b, p), b - a + 1))
ans = 0
for i in range(n - 1):
	(a, b) = (arr[i][0], arr[i + 1][0])
	(x, y) = (arr[i][1], arr[i + 1][1])
	ans += 1 - (1 - a / x) * (1 - b / y)
(a, b) = (arr[0][0], arr[-1][0])
(x, y) = (arr[0][1], arr[-1][1])
ans += 1 - (1 - a / x) * (1 - b / y)
print(ans * 2000)


(n, p) = [int(x) for x in input().split()]
segments = []
for i in range(n):
	segments.append(tuple((int(x) for x in input().split())))
divam = lambda p, s: (s[1] - s[0]) // p + (s[1] % p < s[0] % p or s[0] % p == 0)

def expectation(s1, s2):
	(k1, k2) = (divam(p, s1), divam(p, s2))
	(n1, n2) = (s1[1] - s1[0] + 1, s2[1] - s2[0] + 1)
	return 2000 * (k1 * n2 + k2 * n1 - k1 * k2) / (n1 * n2)
print(sum((expectation(segments[i], segments[(i + 1) % n]) for i in range(n))))


def fu(a):
	return a[1] // p - (a[0] - 1) // p
(n, p) = list(map(int, input().split()))
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
s = 0
for i in range(n):
	s += 1 - (a[i][1] - a[i][0] + 1 - fu(a[i])) / (a[i][1] - a[i][0] + 1) * ((a[(i + 1) % n][1] - a[(i + 1) % n][0] + 1 - fu(a[(i + 1) % n])) / (a[(i + 1) % n][1] - a[(i + 1) % n][0] + 1))
print(s * 2000)


from math import floor, ceil

def mults(a, b, n):
	return max(floor(b / n) - ceil(a / n) + 1, 0)

def prob(a, b, n):
	return 1 - mults(a, b, n) / (b - a + 1)
ans = 0
(n, p) = list(map(int, input().split()))
(firststart, firstend) = list(map(int, input().split()))
prevstart = firststart
prevend = firstend
for i in range(1, n):
	(nextstart, nextend) = list(map(int, input().split()))
	ans += 1 - prob(prevstart, prevend, p) * prob(nextstart, nextend, p)
	prevstart = nextstart
	prevend = nextend
ans += 1 - prob(prevstart, prevend, p) * prob(firststart, firstend, p)
print(2000 * ans)


def ws_ex(p, sharks):
	ex = 0
	(li, ri) = sharks[-1]
	fi = (ri // p - (li - 1) // p) / float(ri - li + 1)
	for (lj, rj) in sharks:
		fj = (rj // p - (lj - 1) // p) / float(rj - lj + 1)
		ex += fi + fj - fi * fj
		(li, ri, fi) = (lj, rj, fj)
	return 2000 * ex

def get_input():
	(n, p) = map(int, input().split())
	sharks = []
	for _ in range(n):
		(l, r) = map(int, input().split())
		sharks.append((l, r))
	return (p, sharks)
(p, sharks) = get_input()
ex = ws_ex(p, sharks)
print('{:.6f}'.format(ex))


(n, p) = map(int, input().split())
ans = 0
x = []
for _ in range(n):
	(l, r) = map(int, input().split())
	x.append((r // p - (l - 1) // p, r - l + 1))
for i in range(n):
	div1 = x[i][1]
	div2 = x[(i + 1) % n][1]
	ans += (1 - (div1 - x[i][0]) / div1 * ((div2 - x[(i + 1) % n][0]) / div2)) * 2000
print(ans)


(n, p) = [int(x) for x in input().split()]
Arr = []
for i in range(n):
	(tmp1, tmp2) = [int(x) for x in input().split()]
	cnt = tmp2 // p - (tmp1 - 1) // p
	Arr.append(cnt / (tmp2 - tmp1 + 1))
Arr.append(Arr[0])
ans = 0.0
for i in range(n):
	p1 = Arr[i]
	p2 = Arr[i + 1]
	ans += p1 + p2 - p1 * p2
print(ans * 2000)


fun = lambda : map(int, input().split())
(n, p) = fun()
a = [0] * n
rt = 0
for i in range(n):
	(l, r) = fun()
	a[i] = (r // p - (l - 1) // p) / (r - l + 1)
for i in range(n):
	rt += a[i] + a[i - 1] - a[i] * a[i - 1]
rt *= 2000
print(rt)


(n, p) = [int(i) for i in input().split()]
b = []
for i in range(n):
	a = [int(i) for i in input().split()]
	if a[0] % p == 0:
		l = a[0] // p
	else:
		l = a[0] // p + 1
	r = a[1] // p
	s = max(0, r - l + 1)
	s /= a[1] - a[0] + 1
	b += [s]
res = 0
for i in range(-1, n - 1):
	res += (b[i] + b[i + 1] - b[i] * b[i + 1]) * 2000
print(res)


(n, p) = map(int, input().split())
prob = []
for _ in range(n):
	(low, up) = map(int, input().split())
	prob.append((up // p - (low - 1) // p) / (up - low + 1))
ans = sum(prob) * 4000
for idx in range(len(prob)):
	ans -= 2000 * prob[idx] * prob[idx - 1]
print(ans)


import sys
(N, p) = list(map(int, input().split()))
l = list()
r = list()
for i in range(0, N):
	(a, b) = list(map(int, input().split()))
	l.append(a)
	r.append(b)
l.append(l[0])
r.append(r[0])
answer = 2000 * N
answer = 0
for i in range(0, N):
	c1 = l[i] // p
	c2 = r[i] // p
	pos1 = c2 - c1
	if l[i] % p == 0:
		pos1 += 1
	total1 = r[i] - l[i] + 1
	bad_pos1 = total1 - pos1
	c1 = l[i + 1] // p
	c2 = r[i + 1] // p
	pos2 = c2 - c1
	if l[i + 1] % p == 0:
		pos2 += 1
	total2 = r[i + 1] - l[i + 1] + 1
	bad_pos2 = total2 - pos2
	answer += 2000 * (1 - bad_pos1 / total1 * bad_pos2 / total2)
print(answer)


from math import floor
(n, p) = list(map(int, input().split()))
result = 0
pb = [0 for i in range(n)]
for i in range(n):
	(a, b) = list(map(int, input().split()))
	pb[i] = 1 - (floor(b / p) - floor((a - 1) / p)) / (b - a + 1)
for i in range(n):
	if i == n - 1:
		result += 2000 * (1 - pb[0] * pb[i])
	else:
		result += 2000 * (1 - pb[i] * pb[i + 1])
print(result)


(n, p) = list(map(int, input().split()))
e = []
for i in range(n):
	(l, r) = list(map(int, input().split()))
	L = -1
	R = 10 ** 9 + 7
	while L != R - 1:
		m = (L + R) // 2
		if m * p < l:
			L = m
		else:
			R = m
	col1 = R
	L = -1
	R = 10 ** 9 + 7
	while L != R - 1:
		m = (L + R) // 2
		if m * p <= r:
			L = m
		else:
			R = m
	col2 = R
	col = r - l + 1
	e.append(1 - (col2 - col1) / col)
sum = 0
for i in range(n):
	sum += 1000 * (1 - e[i] * e[i - 1])
print(sum * 2)


def prob(p, l, r):
	fav = r // p - (l - 1) // p
	return fav / (r - l + 1)
(n, p) = map(int, input().split())
r = []
for i in range(n):
	r.append(list(map(int, input().split())))
ans = 0
for i in range(n):
	j = (i + 1) % n
	in_first = prob(p, r[i][0], r[i][1])
	in_second = prob(p, r[j][0], r[j][1])
	in_neither = (1 - in_first) * (1 - in_second)
	in_either = 1 - in_neither
	ans += 2000 * in_either
print(ans)


(n, p) = map(int, input().split())
prob = [0.0] * n
for i in range(n):
	(l, r) = map(int, input().split())
	prob[i] = 1.0 - (r // p - (l - 1) // p) / (r - l + 1)
ans = 0.0
for i in range(n - 1):
	ans += (1.0 - prob[i] * prob[i + 1]) * 2000
ans += (1.0 - prob[n - 1] * prob[0]) * 2000
print(ans)


def e(l1, r1, l2, r2, p):
	nonprimes_1 = r1 - l1 + 1 - r1 // p + (l1 - 1) // p
	nonprimes_2 = r2 - l2 + 1 - r2 // p + (l2 - 1) // p
	return 1 - nonprimes_1 * nonprimes_2 / ((r1 - l1 + 1) * (r2 - l2 + 1))

def main():
	(n, p) = map(int, input().split())
	l_r = [tuple(map(int, input().split())) for _ in range(n)]
	ans = 0
	for i in range(n):
		ans += e(*l_r[i], *l_r[(i + 1) % n], p)
	print(ans * 2000)
main()


from collections import Counter, defaultdict, deque
import sys
input = sys.stdin.readline

def solve():
	(n, p) = [int(x) for x in input().split()]
	prob = []
	for i in range(n):
		(l, r) = [int(x) for x in input().split()]
		c = r // p - (l - 1) // p
		prob.append(c / (r - l + 1))
	ans = 0
	for i in range(n):
		p = prob[i]
		p1 = 1 - p
		ans += 1000 * (2 * p + p1 * (prob[i - 1] + prob[(i + 1) % n]))
	print(ans)
tt = 1
for test in range(tt):
	solve()


def getMultiplesInRange(start, end, p):
	return int(end / p) - int((start - 1) / p)
(n, p) = map(int, input().split(' '))
ranges = []
answer = 0
for i in range(n):
	(lower, upper) = map(int, input().split(' '))
	ranges.append([lower, upper])
for i in range(n):
	startIndex = i
	endIndex = (i + 1) % n
	multiplesInRangeForFirst = getMultiplesInRange(ranges[startIndex][0], ranges[startIndex][1], p)
	totalNumbersInRangeForFirst = ranges[startIndex][1] - ranges[startIndex][0] + 1
	nonMultiplesInRangeForFirst = totalNumbersInRangeForFirst - multiplesInRangeForFirst
	multiplesInRangeForSecond = getMultiplesInRange(ranges[endIndex][0], ranges[endIndex][1], p)
	totalNumbersInRangeForSecond = ranges[endIndex][1] - ranges[endIndex][0] + 1
	nonMultiplesInRangeForSecond = totalNumbersInRangeForSecond - multiplesInRangeForSecond
	numerator = nonMultiplesInRangeForFirst * nonMultiplesInRangeForSecond
	denominator = totalNumbersInRangeForFirst * totalNumbersInRangeForSecond
	success_probability = (denominator - numerator) / denominator
	answer = answer + success_probability
print(answer * 2000)


(n, p) = map(int, input().split())
(L, R) = ([], [])
for i in range(n):
	(l, r) = map(int, input().split())
	L.append(l)
	R.append(r)
ans = 0
for i in range(n):
	(l1, r1, l2, r2) = (L[i], R[i], L[(i + 1) % n], R[(i + 1) % n])
	(l_1, r_1, l_2, r_2) = (L[i], R[i], L[(i + 1) % n], R[(i + 1) % n])
	if l1 % p > 0:
		l1 += p - l1 % p
	if l2 % p > 0:
		l2 += p - l2 % p
	r1 -= r1 % p
	r2 -= r2 % p
	ans += 2000 * (r2 // p - l2 // p + 1) / (r_2 - l_2 + 1) + 2000 * (r1 // p - l1 // p + 1) / (r_1 - l_1 + 1) - 2000 * (r2 // p - l2 // p + 1) / (r_2 - l_2 + 1) * (r1 // p - l1 // p + 1) / (r_1 - l_1 + 1)
print(ans)


def read_list():
	return [int(i) for i in input().split()]

def new_list(n):
	return [0 for i in range(n)]

def new_matrix(n, m=0):
	return [[0 for i in range(m)] for i in range(n)]

def calc(a, b):
	return (1 - (1 - a) * (1 - b)) * 2000

def in_interval(a, b, p):
	return b // p - (a - 1) // p
(n, p) = read_list()
sh = []
answ = 0
for i in range(n):
	(l, r) = read_list()
	c = in_interval(l, r, p)
	sh.append(c / (r - l + 1))
for i in range(1, n):
	answ += calc(sh[i], sh[i - 1])
answ += calc(sh[0], sh[n - 1])
print(answ)


(n, p) = [int(x) for x in input().split()]
lr = []
for _ in range(n):
	(l, r) = [int(x) for x in input().split()]
	lr.append((l, r))
a = []
for (l, r) in lr:
	a.append(r // p - (l - 1) // p)
res = 0
for i in range(n):
	j = (i + 1) % n
	p = 1 - (lr[i][1] - lr[i][0] + 1 - a[i]) / (lr[i][1] - lr[i][0] + 1) * ((lr[j][1] - lr[j][0] + 1 - a[j]) / (lr[j][1] - lr[j][0] + 1))
	res += p * 2000
print(res)


(n, p) = map(int, input().split())

def prob(l, r, p):
	a = l % p
	b = r % p
	n = (r - l) // p
	if a > b or a == 0 or b == 0:
		n += 1
	return n / (r - l + 1)
pr = list()
for i in range(n):
	(l, r) = map(int, input().split())
	pr.append(prob(l, r, p))
k = pr[-1] * pr[0]
for i in range(n - 1):
	k += pr[i] * 1.0 * pr[i + 1] * 1.0
print(2000.0 * (2.0 * sum(pr) - k))


(t, k) = map(int, input().split())
(n, m) = ([], [])
for i in range(t):
	(x, y) = map(int, input().split())
	n.append(y - x + 1)
	m.append(y // k - (x - 1) // k)
ans = 0
for i in range(t):
	j = (i + 1) % t
	ans += 1 - (n[i] - m[i]) / n[i] * ((n[j] - m[j]) / n[j])
print(ans * 2000)


import sys
lines = sys.stdin.readlines()
(n, p) = map(int, lines[0].strip().split(' '))
ranges = []
for i in range(1, n + 1):
	(l, r) = map(int, lines[i].strip().split(' '))
	ranges.append((l, r))
probs = []
for lr in ranges:
	poss = lr[1] // p - (lr[0] - 1) // p
	probs.append(poss / (lr[1] - lr[0] + 1))
res = 0
for i in range(n):
	res += probs[i] + probs[i - 1] - probs[i] * probs[i - 1]
print(res * 2000)


f = lambda : list(map(int, input().split()))
(n, p) = f()
t = [(l - 1, r) for (l, r) in [f() for i in range(n)]]
t = [(r // p - l // p) / (r - l) for (l, r) in t]
print(2000 * sum((t[i] * (2 - t[i - 1]) for i in range(n))))


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def L():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
(n, p) = L()
A = [L() for i in range(n)]
B = []
for i in range(n):
	(l, r) = A[i]
	a = r // p - l // p + int(l % p == 0)
	b = r - l + 1 - a
	B.append([a, b])
ans = 0
B.append(B[0])
for i in range(n):
	(x, y) = B[i]
	ans += x * 4 / (x + y)
	(z, w) = B[i + 1]
	ans -= 2 * z * x / ((x + y) * (z + w))
print(ans * 1000)
endtime = time.time()


cn = input().split()
count = int(cn[0])
p = int(cn[1])
problist = []
e = 0.0
for i in range(0, count):
	rs = input().split()
	l = int(rs[0])
	r = int(rs[1])
	c = r // p - l // p
	if l % p == 0:
		c = c + 1
	problist.append(c / (r - l + 1.0))
for i in range(1, count):
	e += 2000 * (1 - (1 - problist[i]) * (1 - problist[i - 1]))
e += 2000 * (1 - (1 - problist[0]) * (1 - problist[count - 1]))
print(e)


(n, p) = [int(i) for i in input().split()]
s = []
q = [(0, 0)] * n
for i in range(n):
	(l, r) = [int(i) for i in input().split()]
	s.append((l, r))
for i in range(n):
	q[i] = ((s[i][1] - s[i][1] % p - (s[i][0] + p - 1) // p * p) // p + 1, s[i][1] - s[i][0] + 1)
sm = 0
for i in range(n):
	sm += (1 - (q[i - 1][1] - q[i - 1][0]) / q[i - 1][1] * ((q[i][1] - q[i][0]) / q[i][1])) * 2000
print(sm)


def NewProbabilidad(a, b, c, d, p):
	return ((d - c + 1) * (int(b / p) - int((a - 1) / p)) + ((b - a + 1) * (int(d / p) - int((c - 1) / p)) - (int(b / p) - int((a - 1) / p)) * (int(d / p) - int((c - 1) / p)))) / ((b - a + 1) * (d - c + 1))

def WetSharkAndFlowers(n, p, SharkMatrix):
	i = 0
	matrixTemp = []
	for i in range(len(SharkMatrix)):
		matrixTemp.append([SharkMatrix[i][0], SharkMatrix[i][1]])
	matrixTemp.append([SharkMatrix[0][0], SharkMatrix[0][1]])
	sumProb = 0
	for i in range(len(matrixTemp) - 1):
		sumProb += NewProbabilidad(matrixTemp[i][0], matrixTemp[i][1], matrixTemp[i + 1][0], matrixTemp[i + 1][1], p)
	sumProb *= 2000
	return sumProb

def problem621C():
	(a, b) = input().split()
	n = int(a)
	p = int(b)
	sharkMatrix = []
	i = 0
	while i < n:
		(a, b) = input().split()
		sharkMatrix.append([int(a), int(b)])
		i += 1
	return WetSharkAndFlowers(n, p, sharkMatrix)
print(problem621C())


(n, p) = [int(i) for i in input().split()]
kek = [0] * n
lol = [0] * n
for i in range(n):
	(l, r) = [int(i) for i in input().split()]
	a = ((r // p + 1) * p - l // p * p) // p
	if l % p:
		a -= 1
	lol[i] = r - l + 1
	kek[i] = a
ans = 0
for i in range(n):
	t = (i + 1) % n
	ans += (kek[i] * (lol[t] - kek[t]) + kek[t] * (lol[i] - kek[i]) + kek[i] * kek[t]) * 2000 / (lol[i] * lol[t])
print(ans)


read = lambda : list(map(int, input().split()))
f = lambda x: (x[1] // p - (x[0] - 1) // p) / (x[1] - x[0] + 1)
(n, p) = read()
a = [f(tuple(read())) for i in range(n)]
ans = sum((1 - (1 - a[i]) * (1 - a[i - 1]) for i in range(n))) * 2000
print(ans)


np = [int(u) for u in input().split()]
(n, p) = np
s = [tuple((int(u) for u in input().split())) for i in range(n)]

def count_multiples(l, r, p):
	return r // p - (l - 1) // p

def E_X_i(i):
	i %= n
	l_i = s[i][0]
	l_j = s[i + 1][0]
	r_i = s[i][1]
	r_j = s[i + 1][1]
	p_i = count_multiples(l_i, r_i, p) / (1 + r_i - l_i)
	p_j = count_multiples(l_j, r_j, p) / (1 + r_j - l_j)
	pr = p_i * p_j + (1 - p_i) * p_j + (1 - p_j) * p_i
	return pr * 2 * 1000
s.append(s[0])
E_X = sum((E_X_i(i) for i in range(n)))
print(E_X)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
MOD = 1000000007

def value():
	return tuple(map(float, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, p) = [int(i) for i in input().split()]
a = []
total = 1
for i in range(n):
	(l, r) = value()
	tot = r - l + 1
	div = r // p - l // p + (l % p == 0)
	a.append((tot, div))
	total *= tot
ans = 0
for i in range(n):
	first = a[i]
	second = a[(i + 1) % n]
	tot = first[0] * second[0]
	ans += (first[1] * second[0] + (first[0] - first[1]) * second[1]) / tot
print(ans * 2000)


import unittest
import sys

class Flowers:

	def __init__(self, test_inputs=None):
		it = iter(test_inputs.split('\n')) if test_inputs else None

		def uinput():
			return next(it) if it else sys.stdin.readline().rstrip()
		[self.n, self.p] = map(int, uinput().split())
		(l, s) = (self.n, 2)
		inp = ' '.join((uinput() for i in range(l))).split()
		self.numm = [[int(inp[i]) for i in range(j, l * s, s)] for j in range(s)]
		(self.numa, self.numb) = self.numm

	def prob(self, l, r, p):
		w = r - l + 1
		lm = l % p
		rm = r % p
		n = (r - rm - (l - lm)) // p
		if lm == 0:
			n += 1
		return n / w

	def calculate(self):
		self.pr = []
		for i in range(self.n):
			self.pr.append(1 - self.prob(self.numa[i], self.numb[i], self.p))
		result = 0
		prev = self.pr[-1]
		for p in self.pr:
			result += 1 - p * prev
			prev = p
		return str(result * 2000)

class unitTests(unittest.TestCase):

	def test_single_test(self):
		test = '3 2\n1 2\n420 421\n420420 420421'
		d = Flowers(test)
		self.assertEqual(d.n, 3)
		self.assertEqual(d.p, 2)
		self.assertEqual(d.numa, [1, 420, 420420])
		self.assertEqual(d.prob(2, 5, 3), 0.25)
		self.assertEqual(d.prob(2, 3, 3), 0.5)
		self.assertEqual(d.prob(3, 4, 3), 0.5)
		self.assertEqual(d.prob(3, 3, 3), 1)
		self.assertEqual(d.prob(1, 4, 5), 0)
		self.assertEqual(Flowers(test).calculate(), '4500.0')
		test = '3 5\n1 4\n2 3\n11 14'
		self.assertEqual(Flowers(test).calculate(), '0.0')
		test = ''
		test = ''

	def time_limit_test(self, nmax):
		import random
		import timeit
		test = str(nmax) + ' ' + str(nmax) + '\n'
		numnums = [str(i) + ' ' + str(i + 1) for i in range(nmax)]
		test += '\n'.join(numnums) + '\n'
		nums = [random.randint(1, 10000) for i in range(nmax)]
		test += ' '.join(map(str, nums)) + '\n'
		start = timeit.default_timer()
		d = Flowers(test)
		calc = timeit.default_timer()
		d.calculate()
		stop = timeit.default_timer()
		print('\nTimelimit Test: ' + '{0:.3f}s (init {1:.3f}s calc {2:.3f}s)'.format(stop - start, calc - start, stop - calc))
sys.setrecursionlimit(100000)
if sys.argv[-1] == '-ut':
	unittest.main(argv=[' '])
sys.stdout.write(Flowers().calculate())


try:
	while True:
		(n, p) = list(map(int, input().split()))
		a = [0] * n
		for i in range(n):
			(lower, upper) = list(map(int, input().split()))
			a[i] = (upper // p - (lower - 1) // p) / (upper - lower + 1)
		print(sum((a[i] + (1 - a[i]) * a[i - 1] for i in range(n))) * 2000)
except EOFError:
	pass


(n, p) = list(map(int, input().split()))
(l_1, r_1) = list(map(int, input().split()))
(pre_l, pre_r) = (l_1, r_1)
answer = 0
for i in range(n - 1):
	(l, r) = list(map(int, input().split()))
	now_shark = [l, r]
	x1 = (r // p - (l - 1) // p) / (r - l + 1)
	x2 = (pre_r // p - (pre_l - 1) // p) / (pre_r - pre_l + 1)
	answer += (1 - (1 - x1) * (1 - x2)) * 2000
	(pre_l, pre_r) = (l, r)
x1 = (r_1 // p - (l_1 - 1) // p) / (r_1 - l_1 + 1)
x2 = (pre_r // p - (pre_l - 1) // p) / (pre_r - pre_l + 1)
answer += (1 - (1 - x1) * (1 - x2)) * 2000
print(answer)


(n, p) = map(int, input().split(' '))
lines = [list(map(int, input().split(' '))) for i in range(n)]
porb = [(r // p - (l - 1) // p) / (r - l + 1) for (l, r) in lines]
ans = sum([1 - (1 - porb[i]) * (1 - porb[i - 1]) for i in range(n)]) * 2000
print(ans)


import math
(n, p) = tuple(map(int, input().split()))
expection = 0
probability = [0] * n
for i in range(n):
	(l, r) = tuple(map(int, input().split()))
	nump = math.floor(r / p) - math.ceil(l / p) + 1
	numa = r - l + 1
	probability[i] = nump / numa
for i in range(n):
	left = i - 1
	right = i + 1
	if left == -1:
		left = n - 1
	if right == n:
		right = 0
	p_middle = probability[i]
	p_left = probability[left]
	p_right = probability[right]
	expection += (p_middle + (1 - p_middle) * p_left * p_right) * 2000
	expection += (1 - p_middle) * (p_left * (1 - p_right) + (1 - p_left) * p_right) * 1000
print(str(expection))


from math import floor
(n, p) = input().split()
(n, p) = (int(n), int(p))
res = 0
pb = [0 for i in range(n)]
for i in range(n):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	pb[i] = 1 - (floor(b / p) - floor((a - 1) / p)) / (b - a + 1)
for i in range(n):
	if i == n - 1:
		res += 2000 * (1 - pb[0] * pb[i])
	else:
		res += 2000 * (1 - pb[i] * pb[i + 1])
print(res)


import math

def main():
	(n, p) = (int(x) for x in input().split())
	bounds = [None] * n
	for i in range(n):
		(l, r) = (int(x) for x in input().split())
		bounds[i] = (l, r)
	print(solver(bounds, p))

def solver(bounds, p):
	n = len(bounds)
	probabilities = [0] * n
	for i in range(len(bounds)):
		(l, r) = bounds[i]
		small = math.ceil(l / p)
		large = int(r / p)
		if small > large:
			probabilities[i] = 0
		else:
			probabilities[i] = (large - small + 1) / (r - l + 1)
	total = 0
	for i in range(len(bounds)):
		a = probabilities[i]
		b = probabilities[(i + 1) % n]
		total += 4 * a - 2 * a * b
	return 1000 * total
main()


(n, p) = list(map(int, input().split(' ')))
l = []
r = []
for i in range(n):
	(li, ri) = list(map(int, input().split(' ')))
	l.append(li)
	r.append(ri)
ans = 0
for i in range(n):
	j = (i + 1) % n
	range1 = r[i] - l[i] + 1
	range2 = r[j] - l[j] + 1
	prob1 = r[i] // p - (l[i] - 1) // p
	prob2 = r[j] // p - (l[j] - 1) // p
	ans += 2000 * (prob1 * range2 + prob2 * range1 - prob1 * prob2) / range1 / range2
print(ans)


(n, p) = map(int, input().split())
stats = [[0, 0, 0] for i in range(n)]
for i in range(n):
	(l, r) = map(int, input().split())
	stats[i][0] = stats[i][2] = r - l + 1
	stats[i][1] = r // p - l // p + (1 if l % p == 0 else 0)
	stats[i][2] = stats[i][0] - stats[i][1]
ans = 0
if stats:
	temp = stats[-1]
	stats.insert(0, temp)
	stats.append(stats[1])
for i in range(1, len(stats) - 1):
	ans += stats[i][1] * 2 / stats[i][0] + stats[i][2] * stats[i + 1][1] / (stats[i][0] * stats[i + 1][0]) + stats[i][2] * stats[i - 1][1] / (stats[i][0] * stats[i - 1][0])
print(ans * 1000)


(N, p) = map(int, input().split())
blah = []
for _ in range(N):
	(l, r) = map(int, input().split())
	lp = (l + p - 1) // p
	rp = r // p
	count = rp - lp + 1
	blah.append(count / (r - l + 1))
total = 0
for i in range(-1, N - 1):
	(a, b) = (blah[i], blah[i + 1])
	total += a + b - a * b
print(total * 2000)


import math

def numberOfMultiples(n, z):
	return n // z
(n, p) = map(int, input().split())
f = [0] * n
g = [0] * n
for i in range(n):
	(l, r) = map(int, input().split())
	f[i] = r - l + 1 - (numberOfMultiples(r, p) - numberOfMultiples(l - 1, p))
	g[i] = r - l + 1

def compute_frac_gain(index):
	return 1 - f[index - 1] * f[index] / (g[index - 1] * g[index])
frac_gains = 0
for i in range(1, n):
	frac_gain = compute_frac_gain(i)
	frac_gains += frac_gain
frac_gain = 1 - f[-1] * f[0] / (g[-1] * g[0])
frac_gains += frac_gain
print(frac_gains * 2000)


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def power_set(L):
	cardinality = len(L)
	n = 2 ** cardinality
	powerset = []
	for i in range(n):
		a = bin(i)[2:]
		subset = []
		for j in range(len(a)):
			if a[-j - 1] == '1':
				subset.append(L[j])
		powerset.append(subset)
	powerset_orderred = []
	for k in range(cardinality + 1):
		for w in powerset:
			if len(w) == k:
				powerset_orderred.append(w)
	return powerset_orderred

def fastPlrintNextLines(a):
	print('\n'.join(map(str, a)))

def sortByFirstAndSecond(A):
	A = sorted(A, key=lambda x: x[0])
	A = sorted(A, key=lambda x: x[1])
	return list(A)
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	(n, p) = li()
	res = 0
	s = 0
	divisible = [0] * n
	temp = []
	for i in range(n):
		(l, r) = li()
		divisible[i] = r // p - (l - 1) // p
		temp.append([l, r])
	l1 = []
	for i in range(n):
		j = i + 1
		if j == n:
			j = 0
		(l, r) = temp[i]
		(l2, r2) = temp[j]
		a1 = (r - l + 1 - divisible[i]) / (r - l + 1)
		a2 = (r2 - l2 + 1 - divisible[j]) / (r2 - l2 + 1)
		l1.append(1 - a1 * a2)
	res = 0
	for i in range(n):
		res += l1[i] * 2000
	print(res)
t = 1
for _ in range(t):
	solve()


s = input()
n = int(s[:s.index(' ')])
p = int(s[s.index(' ') + 1:])
xx = [0]
aa = [0]
for i in range(n):
	s = input()
	b = int(s[:s.index(' ')])
	e = int(s[s.index(' ') + 1:])
	xx.append(e // p - b // p + (b % p == 0))
	aa.append(e - b + 1)
xx.append(xx[1])
aa.append(aa[1])
ans = 0
for i in range(1, n + 1):
	ans += 2000 * (1 - (aa[i] - xx[i]) * (aa[i + 1] - xx[i + 1]) / aa[i] / aa[i + 1])
print(ans)


(n, p) = map(int, input().split())

def cal():
	(a, b) = map(int, input().split())
	return (b // p - (a - 1) // p) / (b - a + 1)
ps = [cal() for _ in range(n)]
out = ps[0] + ps[-1] - ps[0] * ps[-1]
for i in range(n - 1):
	out += ps[i] + ps[i + 1] - ps[i] * ps[i + 1]
print(out * 2000)


(n, p) = map(int, input().split())
expectation = 0.0
plist = [0] * n
for i in range(n):
	(l, r) = map(int, input().split())
	(m1, m2) = (l % p, r % p)
	nhits = (r - l) // p
	if m2 < m1 or m1 == 0:
		nhits += 1
	expectation += 2 * nhits / (r - l + 1)
	plist[i] = nhits / (r - l + 1)
for i in range(n - 1):
	expectation -= plist[i] * plist[i + 1]
expectation -= plist[0] * plist[n - 1]
expectation *= 2000
print(expectation)


(n, p) = map(int, input().split())
R = []
c = 0
for i in range(n):
	(x, y) = map(int, input().split())
	r = y // p - (x - 1) // p
	R.append(r / (y - x + 1))
for i in range(len(R)):
	c += 1 - (1 - R[i]) * (1 - R[(i + 1) % len(R)])
print(c * 2000)


(n, p) = map(int, input().split())
ncnt = [0] * n
tot = [0] * n
for i in range(n):
	(l, r) = map(int, input().split())
	cnt = r // p - (l - 1) // p
	notcnt = r - l + 1 - cnt
	tot[i] = r - l + 1
	ncnt[i] = notcnt
ans = (1 - ncnt[n - 1] / tot[n - 1] * (ncnt[0] / tot[0])) * 2000
for i in range(1, n):
	ans += (1 - ncnt[i - 1] / tot[i - 1] * (ncnt[i] / tot[i])) * 2000
print('%.6f' % ans)


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return map(int, input().split())

def solve(l, r, p):
	return r // p - (l - 1) // p
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, p) = mapin()
l = []
r = []
aa = []
ans = 0
for i in range(n):
	(a, b) = mapin()
	l.append(a)
	r.append(b)
for i in range(n):
	temp = solve(l[i], r[i], p)
	aa.append([temp, r[i] - l[i] + 1 - temp])
temp = 0
for i in range(n):
	d = float(aa[i][1] / (r[i] - l[i] + 1))
	e = float(aa[(i + 1) % n][1] / (r[(i + 1) % n] - l[(i + 1) % n] + 1))
	temp += 1 - float(d * e)
print(temp * 2000)


def main():
	(n, p) = map(int, input().split())
	pro = []
	ans = 0

	def union(a, b):
		return a + b - a * b
	for i in range(n):
		(l, r) = map(int, input().split())
		pro.append((r // p - (l - 1) // p) / (r - l + 1))
	for i in range(n):
		ans += union(pro[i], pro[(i - 1) % n]) + union(pro[i], pro[(i + 1) % n])
	print(1000 * ans)
main()


R = lambda : map(int, input().split())
(n, p) = R()
it = [tuple(R()) for _ in range(n)]
it.append(it[0])
lrp = lambda l, r, p: r // p - (l - 1) // p
np = lambda i: lrp(it[i][0], it[i][1], p)
li = lambda i: it[i][1] - it[i][0] + 1
ev = 0
for i in range(n):
	p_i = 1 - np(i) * 1.0 / li(i)
	p_i1 = 1 - np(i + 1) * 1.0 / li(i + 1)
	pr = 1 - p_i * p_i1
	ev += 2000 * pr
print(ev)


import os, sys
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
from math import gcd
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, p) = map(int, input().split())
a = [0] * n
for i in range(n):
	(l, r) = map(int, input().split())
	l -= 1
	a[i] = (r // p - l // p) / (r - l)
ans = 0
for i in range(n - 1):
	ans += 1 - (1 - a[i]) * (1 - a[i + 1])
ans += 1 - (1 - a[-1]) * (1 - a[0])
ans *= 2000
print(ans)


def solve(n, p, flowers):
	ans = 0
	for i in range(n):
		(l1, r1) = flowers[i - 1]
		(l2, r2) = flowers[i]
		p1 = (r1 // p - (l1 - 1) // p) / (r1 - l1 + 1)
		p2 = (r2 // p - (l2 - 1) // p) / (r2 - l2 + 1)
		ans += 2000 * (p1 + p2 - p1 * p2)
	return ans

def main():
	(n, p) = map(int, input().split())
	flowers = [[int(c) for c in input().split()] for _ in range(n)]
	ans = solve(n, p, flowers)
	print(ans)
main()


def read():
	return map(int, input().split())

def solve(n, p, flowers):
	ans = 0
	for i in range(n):
		(l1, r1) = flowers[i - 1]
		(l2, r2) = flowers[i]
		div1 = r1 // p - (l1 - 1) // p
		div2 = r2 // p - (l2 - 1) // p
		diff1 = r1 - l1 + 1
		diff2 = r2 - l2 + 1
		expectation = div1 / diff1 + div2 / diff2 - div1 * div2 / diff1 / diff2
		ans += 2000 * expectation
	return ans

def main():
	(n, p) = read()
	flowers = []
	for _ in range(n):
		(li, ri) = read()
		flowers.append((li, ri))
	ans = solve(n, p, flowers)
	print(ans)
main()


import sys
import math
MAXNUM = math.inf
MINNUM = -1 * math.inf
ASCIILOWER = 97
ASCIIUPPER = 65

def getInt():
	return int(sys.stdin.readline().rstrip())

def getInts():
	return map(int, sys.stdin.readline().rstrip().split(' '))

def getString():
	return sys.stdin.readline().rstrip()

def printOutput(ans):
	sys.stdout.write('%.10f\n' % ans)

def solve(sharks, p):
	probabilities = [0 for _ in range(len(sharks))]
	payout = 0
	for (index, rng) in enumerate(sharks):
		(li, ri) = rng
		totalprimes = ri // p - (li - 1) // p
		totalnums = ri - li + 1
		probabilities[index] = totalprimes / totalnums
	for i in range(len(sharks)):
		a = i % len(sharks)
		b = (i + 1) % len(sharks)
		prob = probabilities[a] + probabilities[b] - probabilities[a] * probabilities[b]
		payout += 2000 * prob
	return payout

def readinput():
	(n, p) = getInts()
	sharks = []
	for _ in range(n):
		sharks.append(list(getInts()))
	printOutput(solve(sharks, p))
readinput()


(n, p) = [int(x) for x in input().split()]
mi = []
for k in range(0, n):
	(l, r) = [int(x) for x in input().split()]
	x = (r // p - (l - 1) // p) / (r - l + 1)
	mi.append(1 - x)
fin = 0
for z in range(0, len(mi)):
	fin += 1 - mi[z] * mi[(z + 1) % n]
print(fin * 2000)


import sys
(n, p) = map(int, sys.stdin.readline().split())
tmp = []
for i in range(n):
	(a, b) = map(int, sys.stdin.readline().split())
	c = a // p * p
	d = b // p * p
	if c < a:
		c += 1
	if c > d:
		tmp.append(0)
	else:
		tmp.append(((d - c) // p + 1) / (b - a + 1))
ans = 0
for i in range(n):
	if i != n - 1:
		ans += 1 - (1 - tmp[i]) * (1 - tmp[i + 1])
	else:
		ans += 1 - (1 - tmp[i]) * (1 - tmp[0])
ans *= 2000
print(ans)


(n, p) = map(int, input().split())
(l, r) = ([0] * (n + 1), [0] * (n + 1))
for i in range(n):
	(lx, rx) = map(int, input().split())
	l[i] = lx
	r[i] = rx
l[n] = l[0]
r[n] = r[0]
a1 = r[0] // p - (l[0] - 1) // p
b1 = r[0] - l[0] + 1
c1 = (b1 - a1) / b1
res = 0
for i in range(1, n + 1):
	a2 = r[i] // p - (l[i] - 1) // p
	b2 = r[i] - l[i] + 1
	c2 = (b2 - a2) / b2
	res += 1 - c1 * c2
	c1 = c2
print(res * 2000)


import re, sys, math, string, operator, functools, fractions, collections
sys.setrecursionlimit(10 ** 7)
dX = [-1, 1, 0, 0, -1, 1, -1, 1]
dY = [0, 0, -1, 1, 1, -1, -1, 1]
RI = lambda : list(map(int, input().split()))
RS = lambda : input().rstrip().split()
mod = 1000000000.0 + 7
(n, p) = RI()
sharks = [0] * n
for i in range(n):
	(l, r) = RI()
	tot = math.floor(r / p) - math.ceil(l / p) + 1
	sharks[i] = 1 - tot / (r - l + 1)
ans = 0
for i in range(n):
	ans += 1 - sharks[i] * sharks[i - 1]
ans *= 2000
print(ans)


(n, p) = map(int, input().split())
k = list()
for _ in range(n):
	(l, r) = map(int, input().split())
	k.append((r // p - l // p + (l % p == 0)) / (r - l + 1))
s = 0.0
for (p, q) in zip(k, k[1:] + [k[0]]):
	s += 2000 * (p + q - p * q)
print(s)