hdu 3816 To Be NUMBER ONE

来源:互联网 发布:湖北广电网络营业厅 编辑:程序博客网 时间:2024/06/05 10:48
这是一道典型的数学题,只要套公式即可。

 1/n=1/(n+1)+1/(1+n)*(n)

2分解成3和6,3分解成4和12,4分解成5和20。。。。注意每次从最小的分解。
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 6 Accepted Submission(s) : 4
Special Judge

Font: Times New Roman | Verdana | Georgia

Font Size:

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 62 4 6 12
 
代码:
#include<iostream>using namespace std;int f[400];int main(){    int i,j,flag;    memset(f,0,sizeof(f));    f[2]=1;    f[3]=1;    f[6]=1;    printf("2 3 6\n");     i=4;     while(i<=18)     {       i++;      for(j=2;j<=i*i;j++)      {         if(f[j]&&!f[j+1]&&!f[(j+1)*j])         {            f[j]=0;            f[j+1]=1;            f[(j+1)*j]=1;            break;         }      }      flag=1;      for(j=2;j<=(i+1)*(i+1);j++)      {        if(f[j])         {          if(flag){ printf("%d",j);flag=0;}          else printf(" %d",j);        }      }     printf("%\n");            }    //system("pause");    return 0;}