Problem Description
One is an interesting integer. This is also an interesting problem. You are assigned with a simple task.<br>Find N (3 &lt;= N &lt;= 18) different positive integers Ai (1 &lt;= i &lt;= N), and<br><center><img src=http://acm.hdu.edu.cn/data/images/C344-1008-1.png></center><br><br>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 <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 Be NUMBER ONE的更多相关文章

  1. JavaScript Math和Number对象

    目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...

  2. Harmonic Number(调和级数+欧拉常数)

    题意:求f(n)=1/1+1/2+1/3+1/4-1/n   (1 ≤ n ≤ 108).,精确到10-8    (原题在文末) 知识点:      调和级数(即f(n))至今没有一个完全正确的公式, ...

  3. Java 特定规则排序-LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  4. Eclipse "Unable to install breakpoint due to missing line number attributes..."

    Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...

  5. 移除HTML5 input在type="number"时的上下小箭头

    /*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...

  6. iOS---The maximum number of apps for free development profiles has been reached.

    真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...

  7. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  8. [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  9. [LeetCode] Number of Boomerangs 回旋镖的数量

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  10. [LeetCode] Number of Segments in a String 字符串中的分段数量

    Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...

随机推荐

  1. vc多文档应用程序窗口初始化,关闭子框架,标题,动态切换

    vc多文档应用程序窗口初始化    http://hi.baidu.com/laocui172/item/8d17a00b252154e1ff240dae      VC 多文档视图: 关闭所有子框架 ...

  2. Sum of Digits / Digital Root

    Sum of Digits / Digital Root In this kata, you must create a digital root function. A digital root i ...

  3. Android开发之应用程序窗体显示状态操作(requestWindowFeature()的应用)

    转自:http://www.cnblogs.com/salam/archive/2010/11/30/1892143.html 我们在开发程序是经常会需要软件全屏显示.自定义标题(使用按钮等控件)和其 ...

  4. 通过 Azure 媒体管理门户开始使用直播流媒体

    Jason Suess Azure媒体服务首席项目经理 几个月前,我们宣布发布 Azure媒体服务直播服务的公共预览版.其实这些直播服务早已被美国国家广播公司体育台用于多项重大体育赛事的多平台直播 ...

  5. 如何组建理想SOA团队

    趋向采用 SOA 软件开发领域的主要发展趋势是从传统软件体系结构过渡到面向服务的体系结构 (SOA).在传统软件体系结构中,将项目视为单个新应用程序的交付.在SOA中,将项目视为集成服务的交付——一些 ...

  6. 【HTML】Beginner8:Table

    1.Table     Abused to lay out pages    The correct use for tables is to do exactly what you would ex ...

  7. aix 文件大小相关查询

    一.aix中查看文件夹占用空间大小 du命令默认是显示当前目录下每个文件以及每个子目录以及下属文件的大小的 用du -sg 可看出当前文件夹的大小,包括文件夹下文件和文件夹(以G为单位):用du -s ...

  8. poj 2892 Tunnel Warfare(线段树)

    Tunnel Warfare Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 7499   Accepted: 3096 D ...

  9. extjs Cannot read property 'dom' of null

    如果你的EXTJS报错: Cannot read property 'dom' of null,那就有可能是因为你的HTML或者JSP文件中的BODY标签里面少了个东西比如代码是: <html& ...

  10. 一分钟快速入门openstack

    一.它是什么,能干什么想认识一个事物,必须先弄明白它是什么,能干什么.首先说一下,openstack是一个搭建云平台的一个解决方案,说他不是个软件,但是我觉得说是一个软件,能够让大家认识更清晰些.op ...