当前位置:网站首页>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; }
边栏推荐
- The difference between MFC for static libraries and MFC for shared libraries
- Leetcode:829. Sum of continuous integers
- LeetCode 144二叉树的前序遍历、LeetCode 114二叉树展开为链表
- Develop industrial Internet with the technical advantages of small programs
- How do I use Google Chrome 11's Upload Folder feature in my own code?
- 241. Design priorities for operational expressions
- 盘点华为云GaussDB(for Redis)六大秒级能力
- 171. Excel 表列序号
- 访问阿里云存储的图片URL实现在网页直接预览略缩图而不直接下载
- Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
猜你喜欢
![5. [WebGIS practice] software operation - service release and permission management](/img/5d/070e207bd96e60ba1846d644d4fb54.png)
5. [WebGIS practice] software operation - service release and permission management
![[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

小程序容器技术与物联网IoT的结合点

访问阿里云存储的图片URL实现在网页直接预览略缩图而不直接下载

整合阿里云短信的问题:无法从静态上下文中引用非静态方法

Idea plug-in backup table

Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C

用小程序的技术优势发展产业互联网

【TA-霜狼_may-《百人计划》】1.2.3 MVP矩阵运算

Leetcode 128 longest continuous sequence (hash set)
随机推荐
[party benefits] jsonobject to string, leave blank
Leetcode:剑指 Offer 59 - I. 滑动窗口的最大值
Visit the image URL stored by Alibaba cloud to preview the thumbnail directly on the web page instead of downloading it directly
Online public network security case nanny level tutorial [reaching out for Party welfare]
166. fractions to decimals
Blueprism registration, download and install -rpa Chapter 1
快速筛选打卡时间日期等数据:EXCEL筛选查找某一时间点是否在某一时间段内
【EI会议】2022年第三届纳米材料与纳米技术国际会议(NanoMT 2022)
Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)
TEC: Knowledge Graph Embedding with Triple Context
Valid brackets (force deduction 20)
8. string conversion integer (ATOI)
You cannot right-click F12 to view the source code solution on the web page
[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st
Ouc2021 autumn - Software Engineering - end of term (recall version)
LeetCode 31下一个排列、LeetCode 64最小路径和、LeetCode 62不同路径、LeetCode 78子集、LeetCode 33搜索旋转排序数组(修改二分法)
Implement pow (x, n) function
168. Excel表列名称
165. 比较版本号
208. 实现 Trie (前缀树)