您的位置:首页 > 博客中心 > 互联网 >

To Be NUMBER ONE

时间:2022-04-27 19:03

Problem Description One is an interesting integer. This is also an interesting problem. You are assigned with a simple task.
Find N (3 <= N <= 18) different positive integers Ai (1 <= i <= N), and



Any possible answer will be accepted.  

 

Input No input file.  

 

Output Your program’s output should contain 16 lines:
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.  

 

Sample Output 2 3 6
2 4 6 12 题目要注意,分解出来的数要小于个数加1的平方; 算法思想 :

 

对分母进行分解:

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
#include
#include
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 {
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;
}

本类排行

今日推荐

热门手游