Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int main()
- {
- ifstream cin("input.txt");
- int x;
- cin>>x;
- string a = "";
- int tmp = x;
- string stmp = "";
- while (tmp != 0)
- {
- char c = tmp%10 + '0';
- stmp = c + stmp;
- tmp/=10;
- }
- a += stmp;
- int i = 1;
- while (x != 1)
- {
- a += ' ';
- i++;
- if (x%2 == 1)
- x = 3*x+1;
- else
- x /=2;
- int tmp = x;
- string stmp = "";
- while (tmp != 0)
- {
- char c = tmp%10 + '0';
- stmp = c + stmp;
- tmp/=10;
- }
- a += stmp;
- }
- cout<<i<<'\n';
- cout<<a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement