Integer Break

Given a positive integer n, break it into the sum of at least two positive integers
and maximize the product of those integers. Return the maximum product you can get.

For example, given n = 2, return 1 (2 = 1 + 1); given n = 10, return 36 (10 = 3 + 3 + 4).

Note: you may assume that n is not less than 2.

Hint:

There is a simple O(n) solution to this problem.
You may check the breaking results of n ranging from 7 to 10 to discover the regularities.

 /*************************************************************************
> File Name: LeetCode343.c
> Author: Juntaran
> Mail: Jacinthmail@gmail.com
> Created Time: Tue 10 May 2016 04:17:35 PM CST
************************************************************************/ /************************************************************************* Integer Break Given a positive integer n, break it into the sum of at least two positive integers
and maximize the product of those integers. Return the maximum product you can get. For example, given n = 2, return 1 (2 = 1 + 1); given n = 10, return 36 (10 = 3 + 3 + 4). Note: you may assume that n is not less than 2. Hint: There is a simple O(n) solution to this problem.
You may check the breaking results of n ranging from 7 to 10 to discover the regularities. ************************************************************************/ #include<stdio.h> int integerBreak( int n )
{
if( n <= )
{
return ;
}
if( n == )
{
return ;
}
int ret = ;
while( n > )
{
ret *= ;
n -= ;
}
return ret*n;
} int main()
{
int n = ;
int ret = integerBreak(n);
printf("%d\n",ret); return ;
}

最新文章

  1. PHP图片加文字水印和图片水印方法(鉴于李老师博客因没加水印被盗,特搜集的办法。希望能有用!)
  2. 【转】SPDY协议
  3. Web1.0、Web2.0、Web3.0的主要区别
  4. Entity Framework 在Vs2012下Update Model From DataBase 失败的问题
  5. 干货:VLDB论文摘要-阿里技术突破性创新
  6. Android视图SurfaceView的实现原理分析
  7. xpath选择器
  8. seq命令
  9. 《Head First 设计模式》学习笔记——工厂模式 + 抽象工厂模式
  10. JavaScript 客户端JavaScript之事件(DOM API 提供模块之一)
  11. Fragment之三:根据屏幕尺寸加载不同的Fragment
  12. Altium designer 10如何设置标题栏
  13. spring mvc 分页
  14. iOS开发之在地图上绘制出你运行的轨迹
  15. jquery带小图的图片轮换效果
  16. mysql基础---日志文件
  17. CF #349 div1 B. World Tour
  18. Java初级面试题
  19. Packt发布了2018年技能提升报告
  20. 修改input标签type=file类型的文字

热门文章

  1. 第二百五十一天 how can I 坚持
  2. sass学习(2)——关于变量
  3. VHDL TestBench基础(转)
  4. getopt使用例子
  5. Unity3D-Baked Lightmapping 示例学习
  6. uva 10152 ShellSort
  7. Educational Codeforces Round 2 B. Queries about less or equal elements 水题
  8. Codeforces Gym 100203G G - Good elements 暴力
  9. URAL 2047 Maths 打表 递推
  10. onClick,onServerClick,onClientClick