#NSQUARE. NSquare Sum ( Easy )
NSquare Sum ( Easy )
Given two integers N (N <= 1018) and a prime number P (1 < P < 1018), find the lowest number x such that there are not N integers greater or equal to 0 whose sum of squares is equal to x.
N = 2, P = 2 x = 3 mod 2 = 1 0 = 02 + 02 1 = 12 + 02 2 = 12 + 12 4 = 22 + 02
Input
The two integers N (1 <= N <= 1018) and a prime number P (1 < P < 1018). You have to print the answer modulo P.
Output
You have to print an integer x mod P (-1 < x < 1018 + 1) that satisfies the problem. If there's no number x, print "Impossible".
Example
Input: 1 3</p>Output: 2
Input: 13 7 Output: Impossible