2011-06-13 回答
自己写的,JAVA程序,你需要建个类,名字是qinheshu,注意大小写。然后复制运行即可。
public class qinheshu {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int max_range=10;//any number will be OK
int p,q,r;
int x1=0,x2=0;
for (int i=2;i<=max_range;i++)
{
p=(int) (3*Math.pow(2, i-1)-1);
q=(int) (3*Math.pow(2, i)-1);
r=(int) (9*Math.pow(2, 2*i-1)-1);
if (isSushu(p)==true && isSushu(q)==true && isSushu(r)==true)
{
x1=(int) (Math.pow(2, i)*p*q);
x2=(int) (Math.pow(2, i)*r);
System.out.println("Find Qinheshu: " + x1+ " and " + x2);
}
}
}
static boolean isSushu(int d){
int i,pd=1;
for(i=2;i
if((d%i)==0){
pd = 0;
break;
}
}
if(pd==1)
return true;
else
return false;
}
}
另附一链接,自己看下亲和数算法:
http://nightwindmath.blog.163.com/blog/static/26008383200722251513562/
追问:
我补充下。要求要用C++编程!
追答:
我没有C++编译器,自己改吧,很简单的。