hdu3826-Squarefree number-(欧拉筛+唯一分解定理)
Squarefree number
Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3691 Accepted Submission(s):
971
divisible by no perfect squares, except 1. For example, 10 is square-free but 18
is not, as it is divisible by 9 = 3^2. Now you need to determine whether an
integer is squarefree or not.
Input
number of test cases.
For each test case, there is a single line contains an
integer N.
Technical Specification
1. 1 <= T <= 20
2. 2
<= N <= 10^18
output "Yes" if N is squarefree, "No" otherwise.
30
75
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<string>
#include<map>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std; ll prime[];
ll cnt,t,n;
int maxx=1e6+;
bool vis[]; void init()
{
memset(vis,true,sizeof(vis));
vis[]=vis[]=false;
cnt=;
for(ll i=;i<=maxx;i++)
{
if(vis[i])
prime[cnt++]=i;
for(ll j=;j<cnt && i*prime[j]<=maxx;j++)
{
vis[ i*prime[j] ]=false;
if( i%prime[j]== ) break;
}
}
} int main()
{
init();
scanf("%lld",&t);
for(ll k=;k<=t;k++)
{
bool flag=false;
scanf("%lld",&n);
for(ll i=;i<cnt && !flag;i++)
{
int num=;
while( n%prime[i]== )///分解质因子
{
n=n/prime[i];
num++;
}
if(num>=)
{
flag=true;
break;
}
}
/*分解完所有小于10^6的质因子,出来后的这个n还大于1的有三种情况
第一种情况,是一个 大于10^6 的素数
第二种情况,是两个 大于10^6 的素数 的乘积,不可能还有第三个大于10^6的质因子
第三种情况,是一个 大于10^6 的素数 的平方,不可能还有第三个大于10^6的质因子
*/
if(!flag && n>)
{
ll temp=(ll)sqrt(n);
if(temp*temp==n)
flag=true;
}
if(flag)
printf("Case %lld: No\n",k);
else
printf("Case %lld: Yes\n",k);
}
return ;
}
hdu3826-Squarefree number-(欧拉筛+唯一分解定理)的更多相关文章
- hdu2421-Deciphering Password-(欧拉筛+唯一分解定理+积性函数+立方求和公式)
Deciphering Password Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 2018南京icpc-J-Prime Game (欧拉筛+唯一分解定理)
题意:给定n个数ai(n<=1e6,ai<=1e6),定义,并且fac(l,r)为mul(l,r)的不同质因数的个数,求 思路:可以先用欧拉筛求出1e6以内的所有质数,然后对所有ai判断, ...
- hdu4497-GCD and LCM-(欧拉筛+唯一分解定理+组合数)
GCD and LCM Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total ...
- noip复习——线性筛(欧拉筛)
整数的唯一分解定理: \(\forall A\in \mathbb {N} ,\,A>1\quad \exists \prod\limits _{i=1}^{s}p_{i}^{a_{i}}=A\ ...
- 欧拉筛,线性筛,洛谷P2158仪仗队
题目 首先我们先把题目分析一下. emmmm,这应该是一个找规律,应该可以打表,然后我们再分析一下图片,发现如果这个点可以被看到,那它的横坐标和纵坐标应该互质,而互质的条件就是它的横坐标和纵坐标的最大 ...
- hdu2973-YAPTCHA-(欧拉筛+威尔逊定理+前缀和)
YAPTCHA Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- Bi-shoe and Phi-shoe(欧拉筛)
Bamboo Pole-vault is a massively popular sport in Xzhiland. And Master Phi-shoe is a very popular co ...
- POJ2909_Goldbach's Conjecture(线性欧拉筛)
Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one p ...
- 【BZOJ 2190】【SDOI 2008】仪仗队 欧拉筛
欧拉筛模板题 #include<cstdio> using namespace std; const int N=40003; int num=0,prime[N],phi[N]; boo ...
随机推荐
- 【eclipse jar包】在编写java代码时,为方便编程,常常会引用别人已经实现的方法,通常会封装成jar包,我们在编写时,只需引入到Eclipse中即可。
Eclipse中导入外部jar包 在编写java代码时,为方便编程,常常会引用别人已经实现的方法,通常会封装成jar包,我们在编写时,只需引入到Eclipse中即可. 工具/原料 Eclipse 需要 ...
- mocha、should、supertest释义
解释参考地址: https://itbilu.com/nodejs/npm/VyrFOe51-.html Mocha模块 Mocha是一个简单.可扩展的用于Node.js和JavaScript的单元测 ...
- spring事务传播实现源码分析
转载. https://blog.csdn.net/qpfjalzm123/article/details/83717367 本文只是对spring事务传播实现的流程进行简单的分析,如有不对之处请指出 ...
- Maven下载私服上的jar包
1.配置M2_HOME/conf/settions.xml <server> <id>maven-public</id> <username>admin ...
- C++学习基础十三——struct和class的区别
来自:http://blog.sina.com.cn/s/blog_48f587a80100k630.html C++中的struct是对C中struct进行了扩展,它不单是一个包含不同数据类型的数据 ...
- mybatis中xml文件的${}和#{}区别
之前的笔记:#{}相当于JDBC的? ${}是字符串连接符,如果入参为普通类型{}中只写value 在项目中要实现所有业务批量提交的功能,实现方式,把表名,表主键字段当做参数传递,在xml文件中全部使 ...
- Linux 创建用户并赋予 Sudo 权限
01,创建账号 => useradd admin 02,赋予密码 => passwd admin 03,修改 sudo 权限文件,使得该用户可以使用 sudo 命令 vim /etc/su ...
- react-native Animated, 旋转动画
Animated 仅封装了四个可以动画化的组件: View.Text.Image.ScrollView 可以使用 Animated.createAnimatedComponent()来封装你自己的组件 ...
- linux配置sphinx
1. 配置索引 cd /usr/local/sphinx/etc/ cp sphinx.conf.dist sphinx.conf //备份配置文件,防止改错 vim sphinx.conf 配置文件 ...
- 查找nginx安装的路径
你可以用这两个命令,找安装启用的路径 netstat -tnlp|grep nginx 然后看到一行记录,复制最后的一个数据(进程ID) ps -aux |grep 进程ID 就可以看到 NINGX的 ...