The first line contain 3 integers which are the answer for N = 3, separated by a single blank.
The following 15 lines are the answer for N = 4 to 18, as the same format.
The sample output is the first two lines of a possible output.
2 4 6 12
对分母进行分解:
n可以分解成 1/n = 1/(n+1) + 1/(n+1)*n
例如 从2 3 6 开始
不能有相同的 所以只能从 2分解成 3 6 前面已经含有了,然后只能从3开始改,每次从最小的开始分解。
下一项变成 2 4 6 12
下一项不能分解 2因为会多出来6 所以应当选择 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;
}