Skip to content

Instantly share code, notes, and snippets.

@henrybear327
Created October 14, 2017 08:06
Show Gist options
  • Save henrybear327/29809f064267ad98b5907198a2ce1420 to your computer and use it in GitHub Desktop.
Save henrybear327/29809f064267ad98b5907198a2ce1420 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int(x.size()))
typedef long long ll;
typedef double db;
int main() {
ll x;
while (scanf(" %lld", &x)) {
if (x == 0) break;
printf("%lld ", x);
ll mx = -1;
int i;
for (i = 0; ; i++) {
if (x & 1) {
x = 3 * x + 1;
}
else {
x = x / 2;
}
mx = max(mx, x);
if (x == 1) {
break;
}
}
printf("%d %lld\n", i + 1, mx);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment