清华1084,整数拆分
2016-03-10 19:57
316 查看
#include<iostream> #include<cstdio> using namespace std; int nums[1000001]; int main(){ nums[0] = 1; nums[1] = 1; nums[2] = 2; nums[3] = 2; for(int i = 4;i<1000001;i++){ if(i%2==1) nums[i] = nums[i-1];//2*i与2*i-1是一样的 else nums[i] = (nums[i-1]+nums[i/2])%1000000000;//当为偶数时,分为拆项中是否有1,没有1的话则与i/2相同,有1,则把1去除,剩下的与i-1一样 } //提前进行%运算,防止溢出 int n; while(scanf("%d",&n)!=EOF){ printf("%d\n",nums ); } }
相关文章推荐
- 原始的爱情
- Android:Service的非绑定式的创建和生命周期
- C++面试(题)
- Unity3D 学习笔记4 —— UGUI+uLua游戏框架
- Android Studio--五大布局
- 杭电2535
- EJB开发第一个无状态会话bean、开发EJBclient
- 致行业初学者:关于某些培训机构,老徐聊几句,也许对你们有用
- JS背景音乐
- C++ map 的两种插入数据方法
- cocos2d-x编译问题集合之error C2440: “类型转换”: 无法从“void (__thiscall ::* )(void)”转换为“
- UVA 156 - Ananagrams
- c/c++之:main函数参数
- 阿里御膳房简介
- JFinal对model及其子类进行单元测试以及快速写出多线程Junit单元测试用例
- 字符串转换为数字
- [置顶] 基于kmeans聚类算法的图像分割
- R-CNN论文笔记《Rich feature hierarchical for accurate object detection and semantic segmentation》
- BZOJ3355: [Usaco2004 Jan]有序奶牛
- 浅谈 C++ 中的 new/delete 和 new[]/delete[]