Hailstone 在32位无符号整数中最大的跳跃次数
2014-04-14 15:45
351 查看
d
运算结果:
#include <iostream> struct num_step { unsigned int n; unsigned int step; }; unsigned int Hailstone(unsigned int n) { unsigned int step = 1; while (1 < n) { n = n & 0x00000001 ? n * 3 + 1 : n >> 1; step++; } return step; } using namespace std; int main(int __argc, const char** __argv) { unsigned int step = 0; cout << "find max step of n in 0 ~ UINT_MAX" << endl; num_step ns = { 0, 0 }; for (unsigned int i = 0; i != UINT_MAX; i++) { step = Hailstone(i); if (step> ns.step) { ns.step = step; ns.n = i; cout <<i << " have current max step: " << step << endl; } } cout << ns.n << " have max step:" << ns.step << endl; return EXIT_SUCCESS; }
运算结果:
find max step of n in 0 ~ UINT_MAX 0 have current max step: 1 2 have current max step: 2 3 have current max step: 8 6 have current max step: 9 7 have current max step: 17 9 have current max step: 20 18 have current max step: 21 25 have current max step: 24 27 have current max step: 112 54 have current max step: 113 73 have current max step: 116 97 have current max step: 119 129 have current max step: 122 171 have current max step: 125 231 have current max step: 128 313 have current max step: 131 327 have current max step: 144 649 have current max step: 145 703 have current max step: 171 871 have current max step: 179 1161 have current max step: 182 2223 have current max step: 183 2463 have current max step: 209 2919 have current max step: 217 3711 have current max step: 238 6171 have current max step: 262 10971 have current max step: 268 13255 have current max step: 276 17647 have current max step: 279 23529 have current max step: 282 26623 have current max step: 308 34239 have current max step: 311 35655 have current max step: 324 52527 have current max step: 340 77031 have current max step: 351 106239 have current max step: 354 142587 have current max step: 375 156159 have current max step: 383 216367 have current max step: 386 230631 have current max step: 443 410011 have current max step: 449 511935 have current max step: 470 837799 have current max step: 525 1117065 have current max step: 528 2234130 have current max step: 529 2978841 have current max step: 532 3433215 have current max step: 587 5425327 have current max step: 598 5649499 have current max step: 613 7532665 have current max step: 616 10043553 have current max step: 619 18064027 have current max step: 623 21409215 have current max step: 631 23682175 have current max step: 642 31576233 have current max step: 645 40096999 have current max step: 650 46340775 have current max step: 691 52970523 have current max step: 747 62779879 have current max step: 755 83706505 have current max step: 758 111608673 have current max step: 761 176369263 have current max step: 772 185804655 have current max step: 785 264733833 have current max step: 788 310322815 have current max step: 790 356319303 have current max step: 800 712638606 have current max step: 801 813500443 have current max step: 806 1084667257 have current max step: 809 2169334514 have current max step: 810 3586423035 have current max step: 811 3586423035 have max step:811 请按任意键继续. . .
相关文章推荐
- 有n个32位无符号整数,求其中异或之后结果最大的两个数
- 某点最大覆盖次数
- 爬网日志中的警告信息:文件达到最大下载次数,The file reached the maximum download limit. Check that the full text of the document can be meani
- 【Kmp求字符串前缀在字符串出现的次数】51nod 1277 字符串中的最大值
- 32位系统的虚拟内存空间最大容量
- Uvalive - 3026 Period (kmp求字符串的最小循环节+最大重复次数)
- 频繁new长时间后操作异常,跟debug版最大new次数限制有关!
- 为什么32位机器最大只能用到4GB内存
- 两算法:求数组元素出现次数和求子数组最大和
- 使用memcache或redis限制某个用户或者某ip用户一段时间内最大投票次数
- 求一组随机数中的最大最小值最少比较次数
- java数组元素重复次数最大值
- python 最大递归次数 RuntimeError: maximum recursion depth exceeded
- java数组元素重复次数及重复次数的最大值
- java练习,,,从键盘输入次数,输出最大值,和
- 算法8:一个整数数组里怎么同时找最大和最小的数,尽量优化比较次数
- 1、 编写一个Java应用程序,对用户输入的任意一组字符如{1,3,4,7,2,1,1,5,2},输出其中出现次数最多且数值最大的字符,并显示其出现次数。
- 两个鸡蛋测试:从100层楼往下扔鸡蛋,求最坏情况下确认保证鸡蛋可以不破的最大楼层所需次数
- 求直线被确定的最大次数
- 【刨根问底】32位/64位系统、地址总线以及最大内存寻址