Birthday Game

All submissions for this problem are available.
Problem Statement
A game is played on an array whose i^{th} value is denoted by arr[i]. The game is defined as follows:
One move is defined as removing any two numbers from the array, 'a' and 'b', and adding to the end of array a new number c such that c = a + b + (a * b).
This is continued alternately between the players until only one number remains, res. The result of the game is res + 1.
We compute the exponent of a number m in the factorization of this result. If this exponent is nonprime, player1 wins otherwise player2 wins.
Srijan and Ankit are going to play this game and because it is Srijan's birthday, he gets to play first. Also, Srijan can choose a nonempty subarray of the given array arr. The game will be played on only this chosen subarray.
Srijan chooses the subarray randomly.
If Srijan has lost despite these advantages, what is the expected value of the exponent of m at the end of game?
Input
The first line contains two spaceseparated integers n(the length of the array) and m. The next line contains n spaceseparated integers, representing the array.
Output
Output a single value, the expected value of the exponent of m, with a maximum error of 10^{6}.
Constraints
1 ≤ n ≤ 10^{5}
1 ≤ arr[i] ≤ 10^{18}
1 ≤ m ≤ 100
m is guaranteed to be a prime number.
Example 1
Input: 5 7 2 5 3 9 4 Output: 0.0
Example 2
Input: 2 3 49 50 Output: 0.0
Author:  savy1 
Tags  savy1 
Date Added:  28022015 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 