Problem Descriptionone is an interesting integer. This was also an interesting problem. You is assigned with a simple task.<br>find N (3 <= N <=) different positive integers Ai (1 &l t;= i <= N), and<br><center> </center><br><br>any possible answer'll be accepted.
Inputno input file.
Outputyour program ' s output should contain lines:
The first line contain 3 integers which is the answer for N = 3, and separated by a single blank.
The following lines is the answer for N = 4 to +, as the same format.
The sample output is the first and the lines of a possible output.
Sample Output2 3 6
2 4 6 12 The problem should be noted that the number of decomposition is less than the number plus 1 square; algorithm idea:
To decompose the denominator:
n can be decomposed into 1/n = 1/(n+1) + 1/(n+1) *n
For example starting from 2 3 6
Can not have the same so can only be decomposed from 2 to 3 6 is already contained, and then only from the beginning of 3 to change, each time from the smallest start decomposition.
Next item becomes 2 4 6 12
The next item cannot be decomposed 2 because it will come out 6 so you should choose 2 5 6 12 20
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace Std;
int main ()
{int a[400],i,j,flag;
memset (A,0,sizeof (a));
A[2]=1;
A[3]=1;
A[6]=1;
printf ("2 3 6\n");
i=4;
while (i<=18)
{i++;
for (j=2;j<i*i;j++)
{
if (a[j]&&!a[j+1]&&!a[(j+1) *j])
{
a[j]=0;
A[j+1]=1;
a[(j+1) *j]=1;
Break
}
}
flag=1;
For (j=2;j< (i+1) * (i+1); j + +)
{
if (A[j])
{
if (flag)
{
printf ("%d", j);
flag=0;
}
Else
printf ("%d", j);
}
}
printf ("\ n");
}
return 0;
}
To is number one