发布时间:2023-12-17 03:54来源:www.sf1369.com作者:宇宇
//---------------------------------------------------------------------------
#include<stdio.h>
#define HIGH 10000
#define LOW 6
int p(int a) /*寻找a的亲密数,找到则返回该亲密数,否则返回-1*/
{
int i;
int suma=0,sumb=0;
for (i=1; i < a; i++) {
suma+=(a%i)?0:i;
}
for (i=1; i<suma; i++) {
sumb+=(suma%i)?0:i;
}
return (a==sumb&&a!=suma)?suma:-1;
}
int main(void)
{
int a=LOW,b;
while (a<HIGH)
if ((b=p(a++))!=-1&&a<b) {
printf(<%d,%d>\n,a-1,b);
}
return 0;
}
//---------------------------------------------------------------------------