Weird Algorithm - Problem link
Solution
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <climits>
#include <cinttypes>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef long int longi;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
template <class T> int size(const T &x) { return x.size(); }
const int INF = 2147483647;
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
longi n;
cin >> n;
while (n != 1) {
cout << n << ' ';
if (n % 2 == 0) n /= 2;
else n = n * 3 + 1;
}
cout << 1 << endl;
return 0;
}
Top comments (0)