角谷猜想

This commit is contained in:
2025-08-04 11:54:51 +08:00
parent 62dcfa5215
commit d5aba6e9f9

View File

@@ -1,20 +1,22 @@
#include "iostream" #include "iostream"
using namespace std; using namespace std;
int n, r, s = 0, t = 1; int n;
int main() { int main() {
cin >> n; cin >> n;
while (n > 0) { if (n != 1) {
r = n % 10; // 将原数的最后一位取出 while (n > 1) {
n = n / 10; if (n % 2 == 0) {
if (r == 0) { n = n / 2;
continue; } else {
} else { n = n * 3 + 1;
s += r * t; // 将 尾数r 乘上 位权 加到 新数s里 }
t *= 10; // 下一次的数字在更高一位 cout << n << " ";
} }
cout << endl << "END";
} else {
cout << "END";
} }
cout << s << endl;
return 0; return 0;
} }