Hailstone 在32位无符号整数中最大的跳跃次数

#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
请按任意键继续. . .


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值