CF621C.Wet Shark and Flowers

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

Each shark will grow some number of flowers sis_{i} . For ii -th shark value sis_{i} is random integer equiprobably chosen in range from lil_{i} to rir_{i} . Wet Shark has it's favourite prime number pp , and he really likes it! If for any pair of neighbouring sharks ii and jj the product sisjs_{i}·s_{j} is divisible by pp , then Wet Shark becomes happy and gives 10001000 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.

输入格式

The first line of the input contains two space-separated integers nn and pp ( 3<=n<=100000,2<=p<=1093<=n<=100000,2<=p<=10^{9} ) — the number of sharks and Wet Shark's favourite prime number. It is guaranteed that pp is prime.

The ii -th of the following nn lines contains information about ii -th shark — two space-separated integers lil_{i} and rir_{i} ( 1<=li<=ri<=1091<=l_{i}<=r_{i}<=10^{9} ), the range of flowers shark ii can produce. Remember that sis_{i} is chosen equiprobably among all integers from lil_{i} to rir_{i} , inclusive.

输出格式

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 10610^{-6} .

Namely: let's assume that your answer is aa , and the answer of the jury is bb . The checker program will consider your answer correct, if .

输入输出样例

  • 输入#1

    3 2
    1 2
    420 421
    420420 420421
    

    输出#1

    4500.0
    
  • 输入#2

    3 5
    1 4
    2 3
    11 14
    

    输出#2

    0.0
    

说明/提示

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

Consider the first sample. First shark grows some number of flowers from 11 to 22 , second sharks grows from 420420 to 421421 flowers and third from 420420420420 to 420421420421 . There are eight cases for the quantities of flowers (s0,s1,s2)(s_{0},s_{1},s_{2}) each shark grows:

  1. (1,420,420420)(1,420,420420) : note that s0s1=420s_{0}·s_{1}=420 , s1s2=176576400s_{1}·s_{2}=176576400 , and s2s0=420420s_{2}·s_{0}=420420 . For each pair, 10001000 dollars will be awarded to each shark. Therefore, each shark will be awarded 20002000 dollars, for a total of 60006000 dollars.
  2. (1,420,420421)(1,420,420421) : now, the product s2s0s_{2}·s_{0} is not divisible by 22 . Therefore, sharks s0s_{0} and s2s_{2} will receive 10001000 dollars, while shark s1s_{1} will receive 20002000 . The total is 40004000 .
  3. (1,421,420420)(1,421,420420) : total is 40004000
  4. (1,421,420421)(1,421,420421) : total is 00 .
  5. (2,420,420420)(2,420,420420) : total is 60006000 .
  6. (2,420,420421)(2,420,420421) : total is 60006000 .
  7. (2,421,420420)(2,421,420420) : total is 60006000 .
  8. (2,421,420421)(2,421,420421) : total is 40004000 .

The expected value is .

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

首页