NSQUARE - 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

Output:
2
Input:
13 7

Output:
Impossible

Added by:Mateus Dantas [ UFCG ]
Date:2012-09-30
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM32-GCC MAWK BC C-CLANG NCSHARP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JS-MONKEY JULIA KTLN NIM NODEJS OBJC OBJC-CLANG OCT PICO PROLOG PYPY PYPY3 PY_NBC R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET
Resource:Rafael Perrela

hide comments
2012-09-30 23:28:41 Francky
I took care about long long, and output mod p, with "\n" at the end. Curious, I thought this problem was extremely easy, so easy that we can't say anything without spoiling !!!
2012-09-30 23:28:41 Damian Straszak
I guess judge is not strict, my code got accepted with "\n" at the end. Care about long longs and output modulo p.
2012-09-30 23:28:41 Francky
@MateusDantas : please tell me what's wrong ; trailing "\n" ? or just tell me if I misunderstood the problem. My code is commented. Is judge strict ???
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.