Squarefree number

Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1984    Accepted Submission(s):
526

Problem Description
In mathematics, a squarefree number is one which is
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
The first line contains an integer T indicating the
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
For each test case, output the case number first. Then
output "Yes" if N is squarefree, "No" otherwise.
 
Sample Input
2
30
75
 
Sample Output
Case 1: Yes
Case 2: No
 
Author
hanshuai
采用如果素因子超过2次,NO。这个很好理解。
这样还是会超时。10^18次方,最坏的情况下10^9次方。
但是,我们只需要枚举10^6内的素数就可以。为什么?
 
假如n 有(10^6,10^9)的一个素因子平方构成 ,不在10^6范围,但是可能直接开方判断即可。
还有假如是(10^,10^9)的一个素因子平方*a构成,则a必在10^6内。不然数字就超过10^18次方了。
我们用[1,10^6]内的素数,刷一遍的时候,就可能除去a,然后又可以开方,直接判断就行。
 #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<math.h>
using namespace std;
typedef __int64 LL; bool s[];
LL prime[],len;
void init()
{
int i,j;
len=;
memset(s,false,sizeof(s));
for(i=;i<=;i++)
{
if(s[i]==true)continue;
prime[++len]=i;
for(j=i*;j<=;j=j+i)
s[j]=true;
}
}
LL Euler(LL n)
{
LL i,num;
for(i=;prime[i]*prime[i]<=n && i<=len;i++)
{
if(n%prime[i]==)
{
num=;
while(n%prime[i]==)
{
n=n/prime[i];
num++;
if(num>=) return ;
}
}
}
return n;
}
int main()
{
init();
int T,t;
LL n;
scanf("%d",&T);
for(t=;t<=T;t++)
{
scanf("%I64d",&n);
LL ans = Euler(n);
if(ans==)
{
printf("Case %d: No\n",t);
}
else
{
LL cur=(LL)sqrt(ans*1.0);
if(cur*cur==ans)printf("Case %d: No\n",t);
else printf("Case %d: Yes\n",t);
}
}
return ;
}

hdu 3826的更多相关文章

  1. HDU 3826 Squarefree number ( 唯一分解定理 )

    题目链接 题意 : 给出一个数.问其能不能被任何一个平方数整除.如果可以则输出 No 即不是 Square-free Number .否则输出 Yes 分析 : 首先 N 有 1e18 那么大.不能暴 ...

  2. hdu 1573 X问题 (非互质的中国剩余定理)

    X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  3. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  5. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  6. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  8. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  9. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

随机推荐

  1. codevs 1202 求和

    http://codevs.cn/problem/1202/ 1202 求和  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 青铜 Bronze 题解       题目描述 D ...

  2. C# eval()函数浅谈

    <%# Bind("Subject") %> //绑定字段 <%# Container.DataItemIndex + 1%> //实现自动编号<%# ...

  3. 手动写的第一个eChart代码

    手动写的第一个eChart代码 ,第一感觉,杂乱无章 <!doctype html> <html> <head> <meta charset="UT ...

  4. paper 62:高斯混合模型(GMM)参数优化及实现

    高斯混合模型(GMM)参数优化及实现 (< xmlnamespace prefix ="st1" ns ="urn:schemas-microsoft-com:of ...

  5. paper 1:图像特征提取

    特征提取是计算机视觉和图像处理中的一个概念.它指的是使用计算机提取图像信息,决定每个图像的点是否属于一个图像特征.特征提取的结果是把图像上的点分为不同的子集,这些子集往往属于孤立的点.连续的曲线或者连 ...

  6. sql查询 所有被锁定的表

    --sql查询  所有被锁定的表 select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName ...

  7. 夺命雷公狗---TP商城----TP之配置环境---1

    下载到tp3.2.3版本后架设到自己的wamp环境下,然后配置虚拟主机,完事后直接开工 环境下创建一个文件夹,然后里面存放这这两个文件即可开始新的旅途了 这里完了,下一步就开始配置index.php文 ...

  8. 给debian安装xfce桌面套装

    首先要有一个debian的基本系统,然后: 1.sudo apt-get install xorg slim xfce4       #xdm   由于目前源里面最新的版本是4.3.99,想安装4.4 ...

  9. 【crunch bang】调整窗口大小

    在终端下,   <super> + 上箭头  == 向上调整大小 <super> + 下箭头(左.右)

  10. VS中快速生成json数据格式对应的实体

    JSON是一种取代XML的数据结构,和xml相比,它更小巧但描述能力却不差,由于它的小巧所以网络传输数据将减少更多流量从而加快速度. JSON就是一串字符串 只不过元素会使用特定的符号标注. {} 双 ...