Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- vector<int> collatz(int x) {
- vector<int> v;
- while (x != 1) {
- if (x % 2 == 0) {
- x /= 2;
- } else {
- x = 3 * x + 1;
- }
- v.push_back(x);
- }
- return v;
- }
- int main() {
- for (;;) {
- int n;
- cin >> n;
- cout << "> steps: " << collatz(n).size() << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment