level 1
贴吧用户_716aV89
楼主
程序:#include<stdio.h>
int main(){
for(int i=1;i<=1000;i++){
int temp=0;
again:
for(int j=1;j<i;j++){
if(i%j==0&&temp==i+1)printf("%d ",j);
else if(i%j==0)temp+=j;
}
if(temp==i){
printf("\n%d its factors are ",i);
temp++;
goto again;
}
}
return 0;
}
运行结果:6 its factors are 1 2 3
28 its factors are 1 2 4 7 14 18
496 its factors are 1 2 4 8 16 31 62 124 248
为什么会在28的因数中出现18。
我是用temp=i+1用于控制输出因数,temp<=i时用于判断i是否是完数,检查了好几遍问了一圈ai后都只会回答我不要用goto

2025年11月17日 09点11分
1
int main(){
for(int i=1;i<=1000;i++){
int temp=0;
again:
for(int j=1;j<i;j++){
if(i%j==0&&temp==i+1)printf("%d ",j);
else if(i%j==0)temp+=j;
}
if(temp==i){
printf("\n%d its factors are ",i);
temp++;
goto again;
}
}
return 0;
}
运行结果:6 its factors are 1 2 3
28 its factors are 1 2 4 7 14 18
496 its factors are 1 2 4 8 16 31 62 124 248
为什么会在28的因数中出现18。
我是用temp=i+1用于控制输出因数,temp<=i时用于判断i是否是完数,检查了好几遍问了一圈ai后都只会回答我不要用goto


