1001.害死人不偿命的(3n+1)猜想
生活随笔
收集整理的這篇文章主要介紹了
1001.害死人不偿命的(3n+1)猜想
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目截圖:
?
思路:
簡單模擬。具體見另一篇博客。
?
代碼:
1 /* 2 1001.害死人不償命的(3n+1)猜想 3 */ 4 5 #include <stdio.h> 6 #include <string.h> 7 #include <math.h> 8 #include <stdlib.h> 9 #include <time.h> 10 11 int main() { 12 int n, cnt=0; // cnt 步數 13 scanf("%d", &n); 14 while(n != 1) { 15 if(n&1) { // 奇數 16 n = (3*n+1)/2; 17 } else { // 偶數 18 n /= 2; 19 } 20 cnt++; 21 } 22 printf("%d", cnt); 23 24 return 0; 25 }?
轉載于:https://www.cnblogs.com/coderJiebao/p/PAT201.html
總結
以上是生活随笔為你收集整理的1001.害死人不偿命的(3n+1)猜想的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据库系统概论王珊编写的第三章学生-课程
- 下一篇: JS DOM事件(常用消息、常用事件、a