No.2192 Last 14 Digits of a Square Number
Problem Statement
You are given as input a non-negative integer $B$ that is at least $2$, and a non-negative integer $N$ less than $B$.
Determine whether there exists a square number whose remainder when divided by $B$ is equal to $N$.
Input
The input is given from standard input in the following format:
$B$ $N$
Constraints
The input satisfies the following constraints:
- $B$ is a non-negative integer between $2$ and $10^{14}$, inclusive
- $N$ is a non-negative integer less than $B$
Output
Print YES if there exists a square number whose remainder when divided by $B$ is equal to $N$, and NO otherwise.
Print a newline at the end.
Sample
Sample 1
Input
100000000000000 0
Output
YES
Examples of square numbers whose remainder when divided by $10^{14}$ is equal to $0$ include $0$ and
$\displaystyle 100000000000000 = 10000000^2 $
.
Sample 2
Input
100000000000000 1
Output
YES
Examples of square numbers whose remainder when divided by $10^{14}$ is equal to $1$ include $1$ and
$\displaystyle 1000000000000200000000000001 = 100000000000001^2 $
.
Sample 3
Input
100000000000000 2
Output
NO
There is no square number whose remainder when divided by $10^{14}$ is equal to $2$.
Sample 4
Input
100000000000000 96290312864656
Output
YES
An example of a square number whose remainder when divided by $10^{14}$ is equal to $96290312864656$ is
$\displaystyle 10596290312864656 = 102938284^2 $
.
Sample 5
Input
100000000000000 95993098537891
Output
NO
There is no square number whose remainder when divided by $10^{14}$ is equal to $95993098537891$.
Sample 6
Input
99999999999973 99876000273817
Output
YES
An example of a square number whose remainder when divided by $99999999999973$ is equal to $99876000273817$ is
$\displaystyle 999999876000003844 = 999999938^2 $
.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。