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. Error applying BeanValidation relational constraints 错误解决

    来自http://blog.csdn.net/sivyer123/article/details/9185325 在hibernate.hbm.xml中加上 <property name=&qu ...

  2. sdutoj 2603 Rescue The Princess

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2603 Rescue The Princess ...

  3. bean中集合属性的配置

    在实际的开发中,有的bean中会有集合属性,如下: package com.sevenhu.domain; import java.util.List; /** * Created by hu on ...

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

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

  5. 夺命雷公狗ThinkPHP项目之----企业网站13之文章列表页的实现(主要是分页的实现)

    列表页这个其实是比较简单的一个,直接遍历除数据即可: public function lists(){ //$mod = M("Article")->select(); // ...

  6. Power Gating的设计(概述)

    Leakage power随着CMOS电路工艺进程,功耗越来越大. Power Domain的开关一般通过硬件中的timer和系统层次的功耗管理软件来进行控制,需要在一下几方面做trade-off: ...

  7. 《zw版·delphi与halcon系列原创教程》hello,zw

    <zw版·delphi与halcon系列原创教程>hello,zw 按惯例,第一个程序是‘hello’ 毕竟,Halcon是专业的图像库,所以我们就不用纯文本版的,来一个专业版.Halco ...

  8. 雅虎工程师提供的CSS初始化代码

    body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,b ...

  9. Python for z/OS

    Install pythondev Install DB2 or server driver package easy_install ibm_db Get license file from tor ...

  10. 鸟哥的linux私房菜学习记录之bash

    当你对计算机输入一个指令时,bash会将指令传送给核心kernel,核心再去调用相关的程序,启动硬件. 如果直接让用户操作操作系统,可能会造成系统的崩溃,所以操作系统通过应用程序来让用户操作系统即壳程 ...