ABCD Code
InterviewTime limit2sMemory limit512 MB
For each four-digit code, check whether the square of its first two digits plus the square of its last two digits leaves remainder 1 modulo 7.
- Level
Easy2 of 10
- Topics
- Math, Implementation, Number theory, Brute force
- Solved
- No attempts yet
Statement
Vasya often visits Petya. To get into Petya's yard, one must enter a code consisting of four digits. Usually the friends went together, but this time Vasya came alone while Petya waits for him at home.
Vasya does not remember the code, but he has several candidates. He also somehow remembers that the square of the number formed by the first two digits of the code, added to the square of the number formed by the last two digits of the code, leaves a remainder of one when divided by seven. That is, if the code is <<>>, where <<>>, <<>>, <<>>, <<>> are some digits, then leaves a remainder of 1 when divided by 7. For example, the code 2843 is one possible code, since , while 8243 is not, since .
Vasya has several candidates for what the code might be. Help him determine which of the candidates can be the code for the entrance to Petya's yard.
Input
The first line of the input contains the number (), the number of code candidates Vasya remembers. Each of the following lines contains four digits, one candidate code per line.
Output
Print lines. On the -th line, print <<YES>> if the -th code can be the code for the entrance to Petya's yard, otherwise print <<NO>>.