Gym 100796K Profact
来源:互联网 发布:如何创建网络连接 编辑:程序博客网 时间:2024/05/16 18:21
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
71238122425
YESYESNOYESYESYESNO
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 1000000set<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;}
- Gym 100796K Profact
- Gym 100796K Profact(爆搜+剪枝)
- 2015-2016 ACM ICPC Baltic Selection Contest K. Profact
- GYM 100685 K
- Gym 100947K-Jpeg
- codeforces [Gym-100814K]
- Gym-101498K
- Gym 101490K
- Gym 101512K
- [Gym-101201K]
- Gym 101490K dp
- Gym 101164.K
- Gym 101398. K
- Gym-100712K-Runtime Error
- Gym 100712K Runtime Error
- Gym 100712K Runtime Error
- Gym 101116K Mixing Bowls
- Codeforces gym 101149 K 想法
- 1029. Median (25)
- Unity编程笔录--Unity Android加密dll
- VS2010远程调试 (2)
- Struts2系统学习(15)Struts2校验框架基本原理分析
- 变长数据项排序
- Gym 100796K Profact
- 创建型模式:工厂方法模式(Factory Method)--分析优缺点
- 在Win7上安装VS2015 RC(候选发布版)失败完美解决方法
- java调度器(重试机制)实现
- 编程师札记第一卷序语
- HDU 1421
- android hal 学习——数据结构整理
- github设置添加ssh
- zcmu_1671