脑子不够用了,-100求助。

B2077 角谷猜想

makeway @ 2024-08-05 15:28:07

*```cpp 代码:#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; while (n != 1) { if (n % 2 == 0){ cout << n << "/2=" << n / 2 << endl; n = n / 2;} else {cout << n << "3+1=" << n 3 + 1 << endl; n = n 3 ;}} else cout << "End" << endl; return 0; }


**

by TeraniRetZiger @ 2024-08-05 15:28:56

@makeway 《n = n * 3

没加一。


by Delayed @ 2024-08-05 15:30:23

#include<iostream>
using namespace std;
long long n;
void sb(long long x)
{
    if (x != 1)
    {
        if (x % 2)
        {
            cout << x << "*3+1=" << x * 3 + 1 << '\n';
            sb(x * 3 + 1);
        }
        else
        {
            cout << x << "/2=" << x / 2 << '\n';
            sb(x / 2);
        }
    }
}
int main()
{
    cin >> n;
    sb(n);
    cout << "End";
    return 0;
}

by Delayed @ 2024-08-05 15:30:46

@makeway


by makeway @ 2024-08-05 15:33:30

@TeraniRetZiger 谢谢大佬。


by guanyue7109 @ 2024-08-10 16:23:31

希丰展?使MD


by yinjunjie2012 @ 2024-08-22 22:26:32

@Delayed 不是哥们,你的函数名是?


by fonglingyueyin @ 2024-08-30 11:20:23

sb:真文明啊!!!!!!!!


by fonglingyueyin @ 2024-08-30 11:21:46

H_n = \sum_{i = 1}^{n} \frac{1}{i}

|