当前位置:网站首页>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; }
边栏推荐
- Idea plug-in backup table
- Jeecgboot output log, how to use @slf4j
- 【TA-霜狼_may-《百人计划》】1.4 PC手机图形API介绍
- 【TA-霜狼_may-《百人计划》】2.3 常用函数介绍
- 409. longest palindrome
- Ouc2021 autumn - Software Engineering - end of term (recall version)
- 392. 判断子序列
- Future of NTF and trends in 2022
- Valentine's Day is nothing.
- The problem of integrating Alibaba cloud SMS: non static methods cannot be referenced from the static context
猜你喜欢

jeecgboot输出日志,@Slf4j的使用方法

How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars

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

【TA-霜狼_may-《百人计划》】2.1 色彩空间

【TA-霜狼_may-《百人计划》】2.2 模型与材质空间

Idea plug-in backup table

衡量两个向量相似度的方法:余弦相似度、pytorch 求余弦相似度:torch.nn.CosineSimilarity(dim=1, eps=1e-08)

FCN full Convolution Network Understanding and Code Implementation (from pytorch Official Implementation)

静态库使用MFC和共享库使用MFC的区别

Asgnet paper and code interpretation 2
随机推荐
Millet College wechat scanning code login process record and bug resolution
Leetcode:剑指 Offer 59 - I. 滑动窗口的最大值
5. [WebGIS practice] software operation - service release and permission management
Quickly filter data such as clock in time and date: Excel filter to find whether a certain time point is within a certain time period
小程序容器技术与物联网IoT的结合点
MFC window scroll bar usage
【TA-霜狼_may-《百人计划》】1.2.3 MVP矩阵运算
171. Excel 表列序号
在 C 中声明函数之前调用函数会发生什么?
409. 最长回文串
在线公网安备案保姆级教程【伸手党福利】
165. compare version numbers
Test function in pychram
idea插件备份表
【TA-霜狼_may-《百人计划》】1.4 PC手机图形API介绍
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
Complete knapsack problem
报错:Plug-ins declaring extensions or extension points must set the singleton directive to true
Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)
The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)