当前位置:网站首页>All in one 1086: Jiaogu conjecture
All in one 1086: Jiaogu conjecture
2022-07-01 03:48:00 【Studying hard】
【 Title Description 】
It is called Jiaogu conjecture , For any positive integer , If it's odd , Then take 3 Add 1, If it's even , Divide by 2, The results are repeated according to the above rules , In the end, you can always get 1. Such as , Suppose the initial integer is 5, The calculation process is as follows 16、8、4、2、1. The program requires an integer , Will be processed to 1 The process output .
【 Input 】
A positive integer N(N <= 2,000,000).
【 Output 】
Enter an integer from to 1 Steps for , Each step is a line , The calculation process is described in each part . The last line outputs "End". If the input is 1, Direct output "End".
【 sample input 】
5
【 sample output 】
5*3+1=16 16/2=8 8/2=4 4/2=2 2/2=1 End
【 Tips 】
no
#include<stdio.h> int main() { int n; scanf("%d", &n); int temp = n; if (n == 1) { printf("End"); } else { if (n % 2 != 0) { n = n * 3 + 1; printf("%d*3+1=%d\n", temp, n); } temp = n; while (1) { n /= 2; if (n != 0) { printf("%d/2=%d\n", temp, n); temp /= 2; } else { printf("End"); break; } if (n % 2 != 0&&n!=1) { temp = n * 3 + 1; printf("%d*3+1=%d\n", n, temp); n = temp; } if (n == 1) { printf("End"); break; } } } return 0; }
边栏推荐
猜你喜欢
4. [WebGIS practice] software operation chapter - data import and processing
Bilinear upsampling and f.upsample in pytorch_ bilinear
Blueprism registration, download and install -rpa Chapter 1
Future of NTF and trends in 2022
Appium自动化测试基础--补充:C/S架构和B/S架构说明
Leetcode 128 longest continuous sequence (hash set)
Promql select time series
Pyramid Scene Parsing Network【PSPNet】论文阅读
Error: plug ins declaring extensions or extension points must set the singleton directive to true
衡量两个向量相似度的方法:余弦相似度、pytorch 求余弦相似度:torch.nn.CosineSimilarity(dim=1, eps=1e-08)
随机推荐
【TA-霜狼_may-《百人计划》】1.2.2 矩阵计算
整合阿里云短信的问题:无法从静态上下文中引用非静态方法
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination
You cannot right-click F12 to view the source code solution on the web page
Review column - message queue
【快捷键】
谷粒学院微信扫码登录过程记录以及bug解决
Implement pow (x, n) function
torch. histc
Leetcode: offer 59 - I. maximum value of sliding window
Cygwin的下载和安装配置
在线公网安备案保姆级教程【伸手党福利】
在 C 中声明函数之前调用函数会发生什么?
Download and installation configuration of cygwin
静态库使用MFC和共享库使用MFC的区别
318. 最大单词长度乘积
Pyramid Scene Parsing Network【PSPNet】论文阅读
6. Z 字形变换
Millet College wechat scanning code login process record and bug resolution