hdu 3816 To Be NUMBER ONE

本文介绍了一种数学题目——特定整数N的分解问题,并提供了一个C++实现的解决方案。该问题要求找到N个不同的正整数,满足一定数学条件。代码通过不断迭代更新整数集合来寻找符合条件的数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这是一道典型的数学题,只要套公式即可。

 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 6
2 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;
}
           
         
            
       

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值