您的位置:首页 > 其它

给定n个整数,从中选出1个或多个,使选出整数的乘积是完全平方数。一共有多少种选法? 例如,{4,6,10,15}有3种4、6、10、15和4、6、10、15。

2016-08-14 17:15 381 查看
#include <stdio.h>
#include <math.h>
int wanquan(int n)
{
__int64 num;
num=sqrt(n);
double x=sqrt(n);
if(num-x==0)
return 1;
else
return 0;
}

int main()
{
int n,count=0;
__int64 *a;
int i,j,k,m;
int t;
scanf("%d",&t);
for(int p=1; p<=t; p++)
{
count=0;
scanf("%d",&n);
a=new __int64
;
j=1; // 2^n-1
for(i=0; i<n; i++)
{
scanf("%d",a+i);
j=j*2;
}
j=j-1;

for(i=1; i<=j; i++)
{
__int64 temp=1;
m=i;
k=0;
while(m)
{
if(m%2)
temp=temp*a[k];
m=m/2;
k++;
}
if(wanquan(temp))
count++;
}
printf("Case #%d:\n%d\n",p,count);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐