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. jquery parent()和parents()区别

    parent(exp) 取得一个包含着所有匹配元素的唯一父元素的元素集合. 你可以使用可选的表达式来筛选. 查找段落的父元素中每个类名为selected的父元素. HTML 代码: <div&g ...

  2. ☀【JS】检测属性

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...

  3. SharePoint 2010在win7 x64 安装

    转:http://kaneboy.blog.51cto.com/1308893/328000 关于<SharePoint 2010应用程序开发指南>,我和杜伟同学正在撰写中,希望下半年早点 ...

  4. InstallShield2008脚本安装制作方法Setup

    //=========================================================================== // //  File Name:    S ...

  5. POJ1680 Currency Exchange SPFA判正环

    转载来源:優YoU  http://user.qzone.qq.com/289065406/blog/1299337940 提示:关键在于反向利用Bellman-Ford算法 题目大意 有多种汇币,汇 ...

  6. POJ ---3070 (矩阵乘法求Fibonacci 数列)

    Fibonacci   Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2  ...

  7. 基于Geoserver配置多图层地图以及利用uDig来进行样式配置

    在GeoServer中配置多个图层的地图相对来说很容易,其步骤为: 1. 进入geoserver 2. 配置相关的FeatureTypes 3. 配置WMS内容,进入以后,主要有以下几个地方需要命名: ...

  8. 2DPlatformer-SLua 编辑器 UI 美化

    在我的开源项目 2DPlatformer-SLua 中,YwLuaMonoBehaviour 是非常重要的一个组件,它负责从 MonoBehaviour 中直接驱动内建的事件到 Lua 中的类和逻辑, ...

  9. C#类方法声明where的用法

    where 子句用于指定类型约束,这些约束可以作为泛型声明中定义的类型参数的变量. 1.接口约束. 例如,可以声明一个泛型类 MyGenericClass,这样,类型参数 T 就可以实现 ICompa ...

  10. 个性CMD设置方法(转载)

    原文地址http://wenku.baidu.com/link?url=DB8X-eHwE_VGtggBmKsBimdzXeGI_6Ga90W9PmX2Px2eUqdXOnq7FhEIzsqBfTqT ...