poj-1207 THE 3n+1 problem
Description
Consider the following algorithm:
1. input n 2. print n 3. if n = 1 then STOP 4. if n is odd then n <-- 3n+1 5. else n <-- n/2 6. GOTO 2
Given the input 22, the following sequence of numbers will be printed 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
It is conjectured that the algorithm above will terminate (when a 1 is printed) for any integral input value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has been verified, however, for all integers n such that 0 < n < 1,000,000 (and, in fact, for many more numbers than this.)
Given an input n, it is possible to determine the number of numbers printed before the 1 is printed. For a given n this is called the cycle-length of n. In the example above, the cycle length of 22 is 16.
For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j.
(是i和j之间数的循环次数最大的)
#include<iostream>
using namespace std;
int bb(int i)
{ int count=1;
while(i!=1)
{
if(i%2==0)i/=2;
else i=i*3+1;
count ++; } return count; }
int main()
{ int a,b;
int q=0;
while(cin>>a>>b)
{
q++;
if(q>=10000)break;
int d=a>b?a:b;
int c=a<b?a:b;
int maxa=0;
for(int j=c;j<=d;j++)
{
int a1=bb(j);
if(maxa<a1)maxa=a1;
}
cout<<a<<" "<<b<<" "<<maxa<<endl; } return 0;
}
poj-1207 THE 3n+1 problem的更多相关文章
- OpenJudge/Poj 1207 The 3n + 1 problem
1.链接地址: http://bailian.openjudge.cn/practice/1207/ http://poj.org/problem?id=1207 2.题目: 总时间限制: 1000m ...
- 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(函数循环长度)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- 烟大 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
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 ...
随机推荐
- 重磅︱R+NLP:text2vec包——New 文本分析生态系统 No.1(一,简介)
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 词向量的表示主流的有两种方式,一种当然是耳熟能 ...
- sparklyr包:实现Spark与R的接口+sparklyr 0.5
本文转载于雪晴数据网 相关内容: sparklyr包:实现Spark与R的接口,会用dplyr就能玩Spark Sparklyr与Docker的推荐系统实战 R语言︱H2o深度学习的一些R语言实践-- ...
- 【linux】启动apache遇到错误:httpd: Could not reliably determine the server's fully qualified domain name
1)进入apache的安装目录:(视个人安装情况而不同) [root@server ~]# cd /usr/local/apache/conf 2)编辑httpd.conf文件,搜索"#Se ...
- R语言︱函数使用技巧(循环、if族/for、switch、repeat、ifelse、stopifnot)
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 后续加更内容: 应用一:if族有哪些成员呢?- ...
- SQL语句报错(一)
SQL语句报错(一) 1.具体报错如下: ORA-01861:文字格式字符串不匹配 01861. 00000 - "literal does not match format string& ...
- Caused by: java.lang.ClassNotFoundException: org.springframework.expression.ExpressionParser
1.错误描述 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -help ...
- MyEclipse保存出现错误
1.错误描述 Errors occurred during the build. Errors running builder 'JavaScript Validator' on project 'S ...
- SDK、JDK、JRE、ADB、AVD到底都是啥?
SDK:Software Development Kit,软件开发工具包是一些被软件工程师用于为特定的软件包.软件框架.硬件平台.操作系统等创建应用软件的开发工具的集合,一般而言SDK即开发 Wind ...
- LinkedHashMap和HashMap
1.HashMap: HashMap里面存入的键值对在取出的时候是随机的,是比较常用的Map.它根据key的HashCode值存储数据,根据key可以直接取出它的值(当然也有冲突的情况,不过遍历链表就 ...
- Python Cookbook(第3版)中文版:15.15 C字符串转换为Python字符串
15.15 C字符串转换为Python字符串¶ 问题¶ 怎样将C中的字符串转换为Python字节或一个字符串对象? 解决方案¶ C字符串使用一对 char * 和 int 来表示, 你需要决定字符串到 ...