角谷猜想
This commit is contained in:
@@ -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 {
|
||||||
s += r * t; // 将 尾数r 乘上 位权 加到 新数s里
|
n = n * 3 + 1;
|
||||||
t *= 10; // 下一次的数字在更高一位
|
|
||||||
}
|
}
|
||||||
|
cout << n << " ";
|
||||||
|
}
|
||||||
|
cout << endl << "END";
|
||||||
|
} else {
|
||||||
|
cout << "END";
|
||||||
}
|
}
|
||||||
cout << s << endl;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user