找出6到5000之间的亲密数对,要求a的因子和等于b的因子和(a!=b),输出a,b 帮我改改我的代码!
#include"stdio.h"voidmain(){longs,a,b,sum1=0,sum2=0;for(a=6;a<=5000;a++){sum1=0;for(s...
#include "stdio.h"
void main()
{
long s,a,b,sum1=0,sum2=0;
for(a=6;a<=5000;a++)
{
sum1=0;
for(s=1;s<a;s++)
{
if(a%s==0)
{
sum1+=s;
printf("%ld %ld\n",a,sum1);
}
}
}
for(b=6;b<=5000;b++)
{
sum2=0;
for(s=1;s<b;s++)
{
if(b%s==0)
{
sum2+=s;
printf("%ld %ld\n",b,sum2);
}
}
}
if(sum1==b&&sum2==a)
{
printf("%ld %ld\n",a,b);
}
} 展开
void main()
{
long s,a,b,sum1=0,sum2=0;
for(a=6;a<=5000;a++)
{
sum1=0;
for(s=1;s<a;s++)
{
if(a%s==0)
{
sum1+=s;
printf("%ld %ld\n",a,sum1);
}
}
}
for(b=6;b<=5000;b++)
{
sum2=0;
for(s=1;s<b;s++)
{
if(b%s==0)
{
sum2+=s;
printf("%ld %ld\n",b,sum2);
}
}
}
if(sum1==b&&sum2==a)
{
printf("%ld %ld\n",a,b);
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询