Hide

Problem B
Elliptic Curve Point Multiplication

Languages en is

Let $p$ be a prime and $a,b\in \mathbb {F}_p$ such that $4a^3 + 27b^2 \not\equiv 0 \pmod{p}$. Let $n \geq 0$ be an integer and $P=(x,y)$ be a point on the elliptic curve $E : y^2 = x^3+ax+b$. Calcuate $nP$ given $p, a, b, x$ and $y$.

Input

Input is three lines. First line consists of three integers, $0 < p < 2^{31}-1$, $0 \leq a < p$ and $0 \leq b < p$, where $p$ is a prime. Second line consist of one integer $0 \leq n \leq 2^{63}-1$. Third line consists of two integers $-1 \leq x_2, y_2 < 2^{31}-1$ where $(x_2,y_2)=(-1,-1)$ is the point at infinity.

Output

Output one line with the coordinates of $nP$ seperated by space. Both coordinates should be $-1$ if the result is the point at infinity.

Sample Input 1 Sample Output 1
5 1 1
4
0 4
3 1
Sample Input 2 Sample Output 2
5 1 1
9
0 4
-1 -1

Please log in to submit a solution to this problem

Log in