After the number of the called number is exactly equal to the sum of factors except itself. For example: 6 = 1 + 2 + 3, where a factor of 1, 2, 6. This problem requires programming to find all the numbers between arbitrary two complete positive integers m and n.
Input format:
Input give two positive integers m and n (1 <m≤n≤10000) in a row, separated by a space.
Output format:
progressive number of each factor outputted to complete a given range of the accumulated factorization form, wherein each complete number representing the number of one row, and the format of "Number of Ends factor = factor 1 + 2 + ... + K factor", ascending order and are by factor analysis. If you do not count them within range, the output "None".
Sample input:
230
Output Sample:
6 1 + 2 + 3 =
28 = 1 + 2 + 4 + 7 + 14
#include<stdio.h>
int main()
{
int n,m,i,j,sum,flag=0;//
scanf("%d %d",&n,&m);
for(i=n;i<=m;i++)
{
sum=1;
if(i==1) continue; //1不是完数
for(j=2;j<i;j++)
{
if(i%j==0)
{
sum=sum+j;
}
}
if(sum==i)
{
printf("%d = 1",sum);
for(j=2;j<i;j++)
{
if(i%j==0)
{
printf(" + %d",j);
}
}
printf("\n");
flag=1;
}
}
if(flag==0)
printf("None");
return 0;
}
Knowledge Point: flag usage