当前位置:网站首页>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; }
边栏推荐
- pytorch nn.AdaptiveAvgPool2d(1)
- How keil displays Chinese annotations (simple with pictures)
- Review column - message queue
- RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
- 详解Spark运行模式(local+standalone+yarn)
- 242. 有效的字母异位词
- Research on target recognition and tracking based on 3D laser point cloud
- Valid brackets (force deduction 20)
- torch. histc
- 165. compare version numbers
猜你喜欢

SEM of C language_ Tvariable type

Millet College wechat scanning code login process record and bug resolution

【TA-霜狼_may-《百人计划》】1.2.3 MVP矩阵运算
![[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st](/img/9f/187ca83be1b88630a6c6fbfb0620ed.png)
[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st

Gorilla/mux framework (RK boot): RPC error code design

ASGNet论文和代码解读2

Leetcode 128 longest continuous sequence (hash set)

快速筛选打卡时间日期等数据:EXCEL筛选查找某一时间点是否在某一时间段内

【TA-霜狼_may-《百人计划》】2.3 常用函数介绍

在线公网安备案保姆级教程【伸手党福利】
随机推荐
[EI search] important information conference of the 6th International Conference on materials engineering and advanced manufacturing technology (meamt 2022) in 2022 website: www.meamt Org meeting time
Valentine's Day is nothing.
【TA-霜狼_may-《百人计划》】1.1 渲染流水线
30. Concatenate substrings of all words
Leetcode: offer 59 - I. maximum value of sliding window
168. Excel表列名称
整合阿里云短信的问题:无法从静态上下文中引用非静态方法
392. 判断子序列
The preorder traversal of leetcode 144 binary tree and the expansion of leetcode 114 binary tree into a linked list
Test function in pychram
【JPCS出版】2022年第三届控制理论与应用国际会议(ICoCTA 2022)
Grid system in bootstrap
[nine day training] content III of the problem solution of leetcode question brushing Report
The problem of integrating Alibaba cloud SMS: non static methods cannot be referenced from the static context
The difference between MFC for static libraries and MFC for shared libraries
165. 比较版本号
Appium自动化测试基础 — APPium基本原理
【EI会议】2022年国际土木与海洋工程联合会议(JCCME 2022)
【TA-霜狼_may-《百人計劃》】1.2.1 向量基礎
Complete knapsack problem