Does it divide?

3.9

114 votes
Easy, Math, Number Theory, Primality test
Problem

Consider a permutation of numbers 1 to N written on a paper. Let’s denote the product of its element as P and the sum of its elements as S. Given a positive integer N, your task is to determine whether P is divisible by S or not. 

Input Format
There will be multiple test cases, each input will start with an integer T (1T100), number of test cases.
Each test case will contain an integer N (1N109), length of the permutation.

Output Format 
For each test case, print “YES” if P is divisible by S, otherwise print “NO”.

Sample Input
2
2
3
Sample Output
NO
YES
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

(1+2) doesn't divide (12), but (1+2+3) divides (123).

Editor Image

?