作业帮 > 综合 > 作业

1) 若正整数A的所有因子(包括1但不包括自身,下同)之和为B,而B的因子之和为A,则称A和B为一对亲密数.例

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/10/09 08:30:58
1) 若正整数A的所有因子(包括1但不包括自身,下同)之和为B,而B的因子之和为A,则称A和B为一对亲密数.例
1) 若正整数A的所有因子(包括1但不包括自身,下同)之和为B,而B的因子之和为A,则称A和B为一对亲密数.例
#include
#include
int fun(int x) ;
int main()
{
int hat ;
printf("请输入想要多少对亲密数") ;
scanf("%d",&hat) ;
int *that1=new int [hat] ;
int *that2=new int [hat] ;
int a,j,b ;
int top=0 ;
for(a=3;;a++)
{
b=fun(a) ;
if(a==b)
continue ;
if(a==fun(b))
{
that1[top]=a ;
that2[top]=b ;
printf("%d%d\n",a,b) ;
top++ ;
if(top%1000==0)
printf("%d\n",top) ;
if(top>hat)
break ;
}
}
FILE *fp=fopen("D:\\亲密数.txt","w");
for(int i=0;i