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 ...
随机推荐
- CPU Rings, Privilege, and Protection.CPU的运行环, 特权级与保护
原文标题:CPU Rings, Privilege, and Protection 原文地址:http://duartes.org/gustavo/blog/ [注:本人水平有限,只好挑一些国外高手的 ...
- solr7.4 tomcat环境下搭建(windows)
-版本solr-7.4.0 -环境 Windows jdk1.8 -启动方式:部署在apache-tomcat-8.5.28,以下简称Tomcat 1. 将solr-7.4.0\server\sol ...
- redis 过期时间与缓存
设置过期时间 redis对于存储的键值可以设置过期时间,对于过期了的键值,redis会自动删除. > OK > get price " > expire price (in ...
- 数据库导入Excel
package com.cfets.ts.s.user.rest; import java.io.File; import java.io.FileInputStream; import java.i ...
- python学习之----深网和暗网
深网是网络的一部分,与浅网(surface Web)对立.浅网是互联网上搜索引擎可以抓 到的那部分网络.据不完全统计,互联网中其实约90% 的网络都是深网.因为谷歌不 能做像表单提交这类事情,也找不到 ...
- LeetCode 2. add two numbers && 单链表
add two numbers 看题一脸懵逼,看中文都很懵逼,链表怎么实现的,点了debug才看到一些代码 改一下,使本地可以跑起来 # Definition for singly-linked li ...
- docekr-image的区别和container;docker run和start,create
copy by: https://www.simapple.com/326.html 容器(container)的定义和镜像(image)几乎一模一样,也是一堆层的统一视角,唯一区别在于容器的最上面那 ...
- 【Python爬虫实战】 使用代理服务器
代理服务器:是一个处于我们与互联网中间的服务器,如果使用代理服务器,我们浏览信息的时候,先向代理服务器发出请求,然后又代理服务向互联网获取信息,再返回给我们使用代理服务器进行信息爬取,可以很好的解决I ...
- 我练就数据分析技能从HR转型为产品经理
本文转自知乎 作者:空白白白白 ----------------------------------------------------- 空白白白白写在前面:当我在奥兰多的时候,一位漂亮的女学员(看 ...
- linux系统安全更新
um --security upgrade 一.参考文档: https://blog.csdn.net/ubuntu64fan/article/details/80927212 二.Linux主机定 ...