当前位置:网站首页>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

边栏推荐
- Varnish foundation overview 3
- Sklearn notes: make_ Blobs generate clustering data
- The Web3 era is coming? Inventory of five Web3 representative projects | footprint analytics
- C language final without failing (Part 1)
- Varnish foundation overview 1
- 手势数字启蒙学习机
- Error reporting in Luban H5 installation
- The unity editor randomly generates objects. After changing the scene, the problem of object loss is solved
- Sentinel source code analysis Part 6 - sentinel adapter module Chapter 4 zuul2 gateway
- Pytorch中transforms的用法整理
猜你喜欢

ES6 one line code for array de duplication

【机器学习Q&A】数据抽样和模型验证方法、超参数调优以及过拟合和欠拟合问题

画画水族馆的应用特色及功能

传统微服务框架如何无缝过渡到服务网格 ASM

C语言 素数对猜想

TP-LINK configure WiFi authentication method for wireless Internet SMS

Preliminary understanding of NVIDIA Jetson nano

What should be paid attention to in the design and production of the Urban Planning Museum

Cookie encryption 8

Cookie encryption 13
随机推荐
Tetris game based on STM32F103
Interview summary
postman 之接口关联
Understanding of int argc, char * * argv in C language main function
Mysql 监控3
How to seamlessly transition from traditional microservice framework to service grid ASM
Storage engine analysis
Varnish foundation overview 4
Varnish 基础概览3
Questions about database: database attachment
cookie加密8
JS anti shake and throttling
js逆向请求参数加密:
C语言 写出这个数
C语言 数组元素循环右移问题
81. search rotation sort array II
[MRCTF2020]Ezpop-1|php序列化
MySQL function
cookie加密8
Pytorch中transforms的用法整理