当前位置:网站首页>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; }
边栏推荐
- [JPCs publication] the Third International Conference on control theory and application in 2022 (icocta 2022)
- [TA frost wolf \u may- hundred people plan] 2.3 introduction to common functions
- What happens when a function is called before it is declared in C?
- idea插件备份表
- Test function in pychram
- Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)
- Feature pyramid networks for object detection
- [ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
- The combination of applet container technology and IOT
- TEC: Knowledge Graph Embedding with Triple Context
猜你喜欢

【TA-霜狼_may-《百人計劃》】2.3 常用函數介紹

Addition without addition, subtraction, multiplication and division

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

Grid system in bootstrap
![5. [WebGIS practice] software operation - service release and permission management](/img/5d/070e207bd96e60ba1846d644d4fb54.png)
5. [WebGIS practice] software operation - service release and permission management
![[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes](/img/be/325f78dee744138a865c13d2c20475.png)
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes

【TA-霜狼_may-《百人計劃》】1.2.1 向量基礎

Unexpected token o in JSON at position 1 ,JSON解析问题

MFC窗口滚动条用法

Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
随机推荐
72. edit distance
214. minimum palindrome string
Pyramid Scene Parsing Network【PSPNet】论文阅读
【伸手党福利】JSONObject转String保留空字段
392. judgment subsequence
30. 串联所有单词的子串
jeecgboot输出日志,@Slf4j的使用方法
171. excel table column No
[party benefits] jsonobject to string, leave blank
【EI会议】2022年第三届纳米材料与纳米技术国际会议(NanoMT 2022)
242. 有效的字母异位词
Develop industrial Internet with the technical advantages of small programs
Blueprism registration, download and install -rpa Chapter 1
10. 正则表达式匹配
Gorilla/mux framework (RK boot): RPC error code design
idea插件备份表
Appium automation test foundation -- supplement: c/s architecture and b/s architecture description
8. 字符串转换整数 (atoi)
Leetcode: offer 59 - I. maximum value of sliding window
392. 判断子序列