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. Java相对路径读取文件

    不管你是新手还是老鸟,在程序中读取资源文件总会遇到一些找不到文件的问题,这与Java底层的实现有关,不能算bug,只要方法得当,问题还是可以解决的. 项目的文件夹结构: repathtest ├─sr ...

  2. php初探

    1.php中的连接符.可以连接多个字符串,相当于java中的+ 2.echo必须与后面的输出内容有至少一个空格 3.php编程中每个结尾都需要添加分号

  3. 线性表基本维护[ACM]

    #include "iostream" #include "string" using namespace std; typedef struct node{ ...

  4. paper 74:MATLAB图像处理_HSV与RGB颜色空间互转

    HSV空间:分别是H(色调)——S(饱和度)——V(亮度) 与HSI颜色空间类似:分别是H(色调)——S(饱和度)——I(强度) 注意: 强度和亮度差不多是一个概念. 饱和度代表的是渗入白光的数量级, ...

  5. 夺命雷公狗mongodb之----mongodb---1---的下载,安装,连接

    首先登录mongodb的官方网站即可进行下载: https://www.mongodb.com/download-center?jmp=nav#community 然后到wamp目录下创建一个mong ...

  6. 夺命雷公狗---微信开发57----微网站之jquery_mobile之入门案例

    这节课我们主要用到到jquery_mobile来实现一个点电影播放网站 jquery_mobile(简称JQM)其实就是基于jquery开发出来的一套移动端框架,适应移动用户端市场对浏览与体验从而进一 ...

  7. libSVM的数据格式

    首先介绍一下 libSVM的数据格式 Label 1:value 2:value -. Label:是类别的标识,比如上节train.model中提到的1 -1,你可以自己随意定,比如-10,0,15 ...

  8. yii2顶部导航使用

    yii2中使用顶部导航的具体方法: 1.视图中调用两个类: use yii\bootstrap\Nav;use yii\bootstrap\NavBar; 2. <?php            ...

  9. 出现“不能执行已释放的Script代码”错误的原因及解决办法

    很多web开发者或许都遇到过这样的问题,程序莫名奇怪出现“不能执行已释放Script的代码”,错误行1,列1.对于这种消息描述不着边,行列描述更是让人迷茫的js错误,相信是所有调试js程序的朋友们最郁 ...

  10. js编写规范

    JavaScript编码规范 Bug----33条 1. 不要使用’==’和’!=’,使用’===’和’!==’替代 等级:Major 原因:==和!=在判断值相等前会判断类型是否相等.这容易因为类型 ...