YTU 1098: The 3n + 1 problem
1098: The 3n + 1 problem
时间限制: 1 Sec 内存限制: 64 MB
提交: 368 解决: 148
题目描述
of numbers will be generated for n = 22: 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 It is conjectured (but not yet proven) that this algorithm will terminate at n = 1 for every integer n. Still, the conjecture holds for all integers up to at least 1, 000,
000. For an input n, the cycle-length of n is the number of numbers generated up to and including the 1. In the example above, the cycle length of 22 is 16. Given any two numbers i and j, you are to determine the maximum cycle length over all numbers between
i and j, including both endpoints.
输入
输出
on one line and with one line of output for each line of input.
样例输入
- 1 10
- 100 200
- 201 210
- 900 1000
样例输出
- 1 10 20
- 100 200 125
- 201 210 89
- 900 1000 174

- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int a,b,i,j=0,m=0,c=0;
- for(; ~scanf("%d%d",&a,&b); m=0)
- {
- for(c=a>b?b:a; c<=(a>b?a:b); c++)
- {
- i=c,j=0;
- for(; i!=1; j++)
- if(i%2==0)i/=2;
- else i=i*3+1;
- m=j>m?j:m;
- }
- printf("%d %d %d\n",a,b,m+1);
- }
- return 0;
- }
YTU 1098: The 3n + 1 problem的更多相关文章
- 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem A: The 3n + 1 problem(水题)
Problem A: The 3n + 1 problem Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 14 Solved: 6[Submit][St ...
- UVa 100 - The 3n + 1 problem(函数循环长度)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- The 3n + 1 problem 分类: POJ 2015-06-12 17:50 11人阅读 评论(0) 收藏
The 3n + 1 problem Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 53927 Accepted: 17 ...
- uva----(100)The 3n + 1 problem
The 3n + 1 problem Background Problems in Computer Science are often classified as belonging to a ...
- 【转】UVa Problem 100 The 3n+1 problem (3n+1 问题)——(离线计算)
// The 3n+1 problem (3n+1 问题) // PC/UVa IDs: 110101/100, Popularity: A, Success rate: low Level: 1 / ...
- 100-The 3n + 1 problem
本文档下载 题目: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pro ...
- PC/UVa 题号: 110101/100 The 3n+1 problem (3n+1 问题)
The 3n + 1 problem Background Problems in Computer Science are often classified as belonging to a ...
- UVA 100 - The 3n+1 problem (3n+1 问题)
100 - The 3n+1 problem (3n+1 问题) /* * 100 - The 3n+1 problem (3n+1 问题) * 作者 仪冰 * QQ 974817955 * * [问 ...
- classnull100 - The 3n + 1 problem
新手发帖,很多方面都是刚入门,有错误的地方请大家见谅,欢迎批评指正 The 3n + 1 problem Background Problems in Computer Science are o ...
随机推荐
- python3--产生偏移和元素:enumerate
之前,我们讨论过通过range来产生字符串中元素的偏移值.而不是那些偏移值处的元素.不过,在有些程序中.我们两者都需要,要用的元素以及值个元素的偏移值.从传统意义来讲,这是简单的for循环,他同时也持 ...
- 本机操作Excel文件提示错误:未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序。
解决办法是: 选择项目-->右键"属性"-->生成-->目标平台-->选择X86或者首选32位
- asp.net静态变量研究
asp.net的webform,请求一个页面,如index.aspx,每一次都会交给不同的线程来处理. 经过个人测试,不管是页面类的静态属性,还是工具类的静态属性,都不会因为session的过期而改变 ...
- 什么是Kubernetes?
刚刚进学校实验室,第一次开会导师和小组同学说了n次Kubernetes,从来没听过,一脸懵逼. Kubernetes也有很多人把它叫K8S, 原文链接:http://omerio.com/2015/1 ...
- NOIP2013D1T3货车运输(最大生成树+倍增lca)
传送门 这道题,先用kruskal求一遍图中的最大生成树. 然后,倍增求lca,求lca的同时求出边权的最小值. #include <cstring> #include <cstdi ...
- 实体类与实体DTO类之间的转换
实体类与实体DTO类之间的转换 实体类与实体DTO类之间的转换 1.通过使用第三方序列化反序列化工具Newtonsoft.Json 2.通过反射实现 3.通过表达式目录树加字典缓存实现 4. 通过表达 ...
- 显示倒计时,为零时自动点击按钮提交【JavaScript实现】
原文发布时间为:2008-10-17 -- 来源于本人的百度文章 [由搬家工具导入] <html> <head> <title>显示倒计时,完毕提交</tit ...
- POJ 1328 Radar Installation【贪心 区间问题】
题目链接: http://poj.org/problem?id=1328 题意: 在x轴上有若干雷达,可以覆盖距离d以内的岛屿. 给定岛屿坐标,问至少需要多少个雷达才能将岛屿全部包含. 分析: 对于每 ...
- IP聚合 ---百度之星(与运算)
Problem Description 当今世界,网络已经无处不在了,小度熊由于犯了错误,当上了度度公司的网络管理员,他手上有大量的 IP列表,小度熊想知道在某个固定的子网掩码下,有多少个网络地址.网 ...
- 使用微软的 ilasm 和 ildasm 对. net程序进行编译和反编译
为了保证示例的完整性,请先准备好一个 c#写的 exe 程序,或者可以使用我提供的 exe 程序也可以(很简单,为了测试这里仅生成了一个带按钮的 winform,单击按钮提示弹窗) Test WinF ...