Home > database >  Odd number
Odd number

Time:10-14

Odd number is an integer so, (1) : in addition to itself the sum of all factors is greater than the number itself (first must be abundance); (2) : in addition to its own set of all factors, no any number of all the subsets and is equal to the number itself, for example, 70 is a strange number, 1000 less than the number of the second strange, find out is 72, the answer is wrong, hope to the predecessors can help me have a look at what went wrong
#include
#include
#include
Void back (int, int n, m int, int [] a);
Int comp (int int u, v);
Int I, j, n, k, sum, flag=1, t, a [1000], num.

Int main ()
{
For (n=71; n<=1000; N++)
{
Int I=0, sum=0, num=0;
for(j=2; j<=n - 1; J++)//find all factors of n
{
If (n % j==0)
{
A [I]=j;//will be an array of n factor exist a [1000] of the
Sum=sum + j;//calculate all factors and
i++;//an array of serial number + 1
Num++;//calculate the size of the array, n number of all the factors that
}
}
Sum=sum + 1;//1 and n factor
A [num]=1;//1 is assigned to an array of a [1000]
If (sum> N)//whether n to win several
{
T=num + 1;//to factor the n number is assigned to the t
Int [t] b={0};//initialize array b, a state of the elements in a given array, similar to the permutation and combination
Back (1, t, sum, a);//starting from the first element, o n a subset of all factors and compared with the sum of
If (flag)//whether the sum of n any subset of the elements and equal
{
Printf (" % d is a strange number \ n ", n);
break;//find the first odd number after stop cycle
}
}
}
return 0;
}

Void back (int, int n, m int, int a [1000])
{
Int b [t];
Int k, Sum=0;
If (i> N)//determine whether a state of the elements in the are sure
{
For (k=1; K<=n; K++)//permutation and combination of the elements of a
{
If (b) [k]//judge the state of the k element
The Sum +=a, [k].

}
Comp (Sum, m);
return;//if meet this condition, you don't have to perform the back for a condition in which the elements in a given operation,
}
{
B [I]=1;//state of permutation and combination of elements in a
The back (I + 1, t, sum, a);
[I] b=0;
The back (I + 1, t, sum, a);
}
return;
}
Int comp (int int u, v)//compare the sum and the sum is equal function
{
If (u==v)
flag=0;
return flag;
}
  • Related