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