雕刻时光

just do it……nothing impossible
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

素数——HDU3826

Posted on 2012-03-26 21:20  huhuuu  阅读(471)  评论(0编辑  收藏  举报

http://acm.hdu.edu.cn/showproblem.php?pid=3826

判断一个数的约数是否开根号为一个整数,存在输出no,否则yes

先1-1000,000之间的素数去试除该数,同一个素数有两次以上将其整除的话,是no,结束

没结束,将余数开根号,看是否是一个整数,是no,否则yes

View Code
#include<stdio.h>
#include<math.h>
#include<string.h>

int ha[1000005],shu[1000005];

int main()
{
int t,i,j,k;
memset(shu,1,sizeof(shu));
shu[1]=0;ha[0]=0;
for(i=2,j=1;i<1000001;i++)
{
if(!shu[i])
continue;
ha[j++]=i;
for(k=(i+i);k<1000001;k+=i)
shu[k]=0;
}

scanf("%d",&t);
__int64 n;
int T=0;
while(t--)
{
T++;
printf("Case %d: ",T);

scanf("%I64d",&n);
int temp;
int ok=0,i;
for(i=1;ha[i]!=0&&n>ha[i];i++)
{
temp=0;
while(n%ha[i]==0)
{
n=n/ha[i];
temp++;
}
if(temp==2)
{
ok=1;
break;
}
}

if(ok==1)
{
printf("No\n");
}
else
{
if(((__int64)sqrt(n*1.0+0.00000001)*(__int64)sqrt(n*1.0+0.00000001))==n)
printf("No\n");
else
printf("Yes\n");
}
}

return 0;
}