Gym 100796K Profact

Alice is bored out of her mind by her math classes. She craves for something much more exciting. That is why she invented a new type of numbers, the profacts. Alice calls a positive integer number a profact if it can be expressed as a product of one or several factorials.

Just today Alice received n bills. She wonders whether the costs on the bills are profact numbers. But the numbers are too large, help Alice check this!

Input

The first line contains a single integer n, the number of bills (1 ≤ n ≤ 105). Each of the next n lines contains a single integer ai, the cost on the i-th bill (1 ≤ ai ≤ 1018).

Output

Output n lines, on the i-th line output the answer for the number ai. If the number ai is a profact, output "YES", otherwise output "NO".

Sample Input

Input
7
1
2
3
8
12
24
25
Output
YES
YES
NO
YES
YES
YES
NO

Hint

这题可以把所有的情况都列举出来然后放入set,然后判断在不在set里面就行了,这里为了爆long long,有一个技巧,判断t乘上k是不是大于10^18,可以用10^18除以t,然后看结果是不是小于k,如果小于,那么t*k>10^18


#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
#define ll __int64
#define inf 0x7fffffff
#define maxn 1000000
set<ll>myset;
set<ll>::iterator it;
ll a[maxn];
ll b[30];
void getnum()
{
    int i,j;
    b[1]=1;
    for(i=2;i<=19;i++){
        b[i]=b[i-1]*i;
    }
}


void init()
{
    myset.clear();
    myset.insert(1);
    getnum();
    for(int i=2;i<=19;i++){
        int tot=0;
        for(it=myset.begin();it!=myset.end();it++){
            tot++;
            a[tot]=*it;
        }
        ll t;
        for(int j=1;j<=tot;j++){
            t=a[j];
            while((1e18)/t>b[i]  ){
                myset.insert(t*b[i]);
                t*=b[i];
            }
        }
    }



}



int main()
{
    int n,m,i,j;
    init();
    scanf("%d",&n);
    ll num;

    int cnt=0;



    for(i=1;i<=n;i++){
        scanf("%I64d",&num);
        if(num==1){
            printf("YES\n");continue;
        }
        it=myset.find(num);
        //printf("--%d\n",*it);
        if(it==myset.end())printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}


posted @ 2015-11-14 18:09  Herumw  阅读(156)  评论(0编辑  收藏  举报