当前位置:网站首页>The (3n+1) conjecture that C language kills people without paying for their lives
The (3n+1) conjecture that C language kills people without paying for their lives
2022-06-30 01:31:00 【Martin の Blog】

Algorithm design ideas
- Judge whether a number is odd or even , May adopt :n%2 Whether it is equal to zero
- Calculate how many times you need to cut , Define a count Variable , Its initial value is 0, Cut once and add one
- Output count value
Code
#include <stdio.h>
int get_step(int n){
int count = 0;
while(n != 1){
if(n%2 == 0){
n /= 2;
}else if(n%2 == 1){
n = (3 * n + 1) / 2;
}
count++;
}
return count;
}
int main(){
int n;
scanf("%d", &n);
int steps = get_step(n);
printf("%d", steps);
return 0;
}
Running results

边栏推荐
- Sentinel source code analysis Part 6 - sentinel adapter module Chapter 4 zuul2 gateway
- Mechanical --nx2007 (UG) -- gap analysis (interference inspection)
- 画画水族馆的应用特色及功能
- The unity editor randomly generates objects. After changing the scene, the problem of object loss is solved
- Varnish foundation overview 10
- App test related tools
- 【图神经网络】图分类学习研究综述[3]:图分类方法评价及未来研究方向
- STC89C52 single chip microcomputer simple calculator design and code demonstration
- Sentinel source code analysis Part 8 - core process - sphu Entry current limiting execution
- How to unify the use of package manager in a project?
猜你喜欢

C语言 数素数

Understand the module function of MES management system

C语言 害死人不偿命的(3n+1)猜想

Unity2D--给动画添加关键帧并绑定事件

C语言 写出这个数

Stimulus reports reporting tool, stimulus creates and builds reports

TP-LINK configure WiFi authentication method for wireless Internet SMS

Embedded exit (review and release)
![[535. encryption and decryption of tinyurl]](/img/b7/7748febe30852ca428fe86b045e9ca.png)
[535. encryption and decryption of tinyurl]

Cookie encryption 11
随机推荐
Understanding of int argc, char * * argv in C language main function
cookie加密11
JS returned content is encoded by Unicode
Mysql 监控5
【推荐系统】基于用户的协同过滤简明原理与代码实现
Varnish 基础概览2
【论文写作】英文论文写作指南
Three text to speech artifacts, each of which is very practical
Sentinel source code analysis Part 6 - sentinel adapter module Chapter 4 zuul2 gateway
cookie加密8
Embedded test template
Sklearn notes: make_ Blobs generate clustering data
Varnish foundation overview 8
GeoTools:WKT、GeoJson、Feature、FeatureCollection相互转换常用工具
[machine learning Q & A] accuracy, accuracy, recall, ROC and AUC
Varnish 基础概览3
[binary tree] maximum binary tree II
Sentinel source code analysis Part 7 - sentinel adapter module - Summary
【机器学习Q&A】数据抽样和模型验证方法、超参数调优以及过拟合和欠拟合问题
How to seamlessly transition from traditional microservice framework to service grid ASM