• 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
    ");continue;
            }
            it=myset.find(num);
            //printf("--%d
    ",*it);
            if(it==myset.end())printf("NO
    ");
            else printf("YES
    ");
        }
        return 0;
    }


  • 相关阅读:
    kubernetes 用到的工具及组件
    kubernetes整个基础环境的准备
    docker可视化管理Portainer
    Docker Swarm的命令
    Docker网络设置及文件挂载
    Docker常见命令
    Docker 中国官方镜像加速
    Docker安装
    k8s中教你快速写一条yaml文件
    Kubernetes CoreDNS 状态是 CrashLoopBackOff 报错
  • 原文地址:https://www.cnblogs.com/herumw/p/9464610.html
Copyright © 2020-2023  润新知