当前位置:网站首页>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; }
边栏推荐
- What happens when a function is called before it is declared in C?
- 6. Z 字形变换
- [深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理
- 10、Scanner. Next() cannot read spaces /indexof -1
- Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
- Addition without addition, subtraction, multiplication and division
- How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars
- torch.histc
- TEC: Knowledge Graph Embedding with Triple Context
- 72. 编辑距离
猜你喜欢
衡量两个向量相似度的方法:余弦相似度、pytorch 求余弦相似度:torch.nn.CosineSimilarity(dim=1, eps=1e-08)
Download and installation configuration of cygwin
Implement pow (x, n) function
[nine day training] content III of the problem solution of leetcode question brushing Report
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
Pyramid scene parsing network [pspnet] thesis reading
【TA-霜狼_may-《百人计划》】1.2.1 向量基础
Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)
pytorch中的双线性插值上采样(Bilinear Upsampling)、F.upsample_bilinear
Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
随机推荐
盘点华为云GaussDB(for Redis)六大秒级能力
Online public network security case nanny level tutorial [reaching out for Party welfare]
【JPCS出版】2022年第三届控制理论与应用国际会议(ICoCTA 2022)
[JPCs publication] the Third International Conference on control theory and application in 2022 (icocta 2022)
Test function in pychram
389. find a difference
Research on target recognition and tracking based on 3D laser point cloud
Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination
Visit the image URL stored by Alibaba cloud to preview the thumbnail directly on the web page instead of downloading it directly
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
Pytorch training deep learning network settings CUDA specified GPU visible
How keil displays Chinese annotations (simple with pictures)
ASGNet论文和代码解读2
How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars
【EI会议】2022年国际土木与海洋工程联合会议(JCCME 2022)
168. Excel表列名称
LeetCode 31下一个排列、LeetCode 64最小路径和、LeetCode 62不同路径、LeetCode 78子集、LeetCode 33搜索旋转排序数组(修改二分法)
详解Spark运行模式(local+standalone+yarn)
Ouc2021 autumn - Software Engineering - end of term (recall version)
208. implement trie (prefix tree)