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
7
1
2
3
8
12
24
25
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;
}
Gym 100796K Profact的更多相关文章
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Gym 100917J---dir -C(RMQ--ST)
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...
- Gym 101102D---Rectangles(单调栈)
题目链接 http://codeforces.com/gym/101102/problem/D problem description Given an R×C grid with each cel ...
- Gym 101102C---Bored Judge(区间最大值)
题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...
随机推荐
- 【Spring】Spring 入门
Spring 入门 文章源码 Spring 概述 Spring Spring 是分层的 Java SE/EE 应用全栈式轻量级开源框架,以 IOC(Inverse Of Control,反转控制)和 ...
- Flutter 基础组件:输入框和表单
前言 Material组件库中提供了输入框组件TextField和表单组件Form. 输入框TextField 接口描述 const TextField({ Key key, // 编辑框的控制器,通 ...
- java8新特性之stream流
Stream 流是 Java 8 提供给开发者一套新的处理集合的API,他把我们将要处理的集合作为流,就像流水线一样,我们可以对其中的元素进行筛选,过滤,排序等中间操作,只不过这种操作更加简洁高效. ...
- XSS-labs通关挑战(xss challenge)
XSS-labs通关挑战(xss challenge) 0x00 xss-labs 最近在看xss,今天也就来做一下xss-labs通过挑战.找了好久的源码,终于被我给找到了,因为在GitHub上 ...
- CopyOnWriteArrayList 读写分离,弱一致性
为什么会有CopyOnWriteArrayList? 我们知道ArrayList和LinkedList实现的List都是非线程安全的,于是就有了Vector,它是基于ArrayList的线程安全集合, ...
- kubernets之Replication Controller
一 Replication Controller的介绍 pod可能会由于各种原因消失和多出来,例如node节点去除集群或者人为的手工创建,所以为了方便和管理pod的数量,k8s里面 的另外 ...
- bash shell关联数组总结
[原创]本博文为原创博文,引用或转发请注明原始出处和链接:https://www.cnblogs.com/dingbj/p/dict_array.html 什么是关联数组? 关联数组相对于索引数组,又 ...
- 使用gui_upload的总结
今天使用gui_upload函数将文本文件的内容读取到内表.出现了一个问题,总是程序宕掉,出项的提示是 Type conflict when calling a function module. 原来 ...
- 05. struts2中为Action属性注入值
概述 struts2为Action中的属性提供了依赖注入功能 在struts2的配置文件中,我们可以很方便地为Action中的属性注入值.注意:属性必须提供get,set方法. 配置 <acti ...
- JavaScript中的深拷贝和浅拷贝!【有错误】还未修改!请逛其他园子!
JavaScript中的深拷贝和浅拷贝! 浅拷贝 1.浅拷贝只是拷贝一层,更深层次对象级别的只拷贝引用.{也就是拷贝的是地址!简而言之就是在新的对象中修改深层次的值也会影响原来的对象!} // 2.深 ...