Repository navigation
Expand file tree
/
Copy path01)Weird_Algorithm.cpp
More file actions
88 lines (83 loc) · 3.51 KB
/
Copy path01)Weird_Algorithm.cpp
File metadata and controls
88 lines (83 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
const int MAX = 8000000000000000064LL;
const int MIN = -8000000000000000064LL;
#define mod ((int)1e9+7)//((int)1e18+7)//998244353//
#define M_PI 3.14159265358979323846
#define ishu ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define all(c) c.begin(),c.end()
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define I insert
#define vl vector<ll>
#define vi vector<ll>
#define pll pair <int , int>
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define Fill(a, b) memset(a, b, sizeof(a))
#define SORT(v) sort(v.begin(), v.end());
#define SORTG(v) sort(v.begin(), v.end(), greater<ll>());
#define loop(i, a, b) for(ll i=a; i<b; i++)
#define input(arr,n) for(ll i=0;i<n;++i) cin>>arr[i];
#define display(v) for (auto k : v){cout << k <<" ";} cout<<endl;
#define input2(v, r, c) for (ll i = 0; i < r; i++){for (ll j = 0; j < c; j++)cin >> v[i][j];}
#define display2(V) for(auto it : V) { for (auto val : it) { cout<<val<<" ";} cout<<endl;}
int exp(int x, int y, int p) {x %= p; int res = 1; while (y) {if (y % 2) res = (res * x % p) % p; x = (x * x) % p; y /= 2; } return res;}
int expo(int x, int y) { int res = 1; while (y) {if (y % 2) res = (res * x % mod) % mod; x = (x * x) % mod; y /= 2; } return res;}
int add(int a, int b) {return (a % mod + b % mod + mod) % mod;}
int sub(int a, int b) {return (a % mod - b % mod + mod) % mod;}
int mul(int a, int b) {return ((a % mod) * (b % mod) + mod) % mod;}
int inv(int x) {return expo(x, mod - 2);}
int xyp(int x,int y){int res=1;while(y>0){if(y%2==1) res=(res*x)%mod;x=(x*x)%mod;y/=2;}return res%mod;}
// int fact[1000007]={0};
// int ncr(int n,int r) {if (r > n)return 0; int res=1; res=fact[n]; res=(res*(xyp(fact[r],mod-2)))%mod; res=(res*(xyp(fact[n-r],mod-2)))%mod; return res;}
// int npr(int n,int r) {int res=1; res=fact[n]; res=(res*(xyp(fact[n-r],mod-2)))%mod; return res; }
//--------------------------------------------INLINE FUNCTIONS-------------------------------------------------------------//
inline ll gcd(ll a, ll b) {if (b == 0) return a; return gcd(b, a % b);}
inline ll lcm(ll a, ll b) {return (a / gcd(a, b) * b);}
//-------------------------------------------------------------------------------------------------------------------//
template<typename T>
istream& operator >> (istream& in, vector<T>& v) {
for (auto& i : v) in >> i;
return in;
}
void yes(){cout<<"YES"<<endl;}void no(){cout<<"NO"<<endl;}
//bool prime[(int)((1e7) + 20)];
//bool sieve
//void sieve(int n){memset(prime,true,sizeof(prime) );for(int p=2;p*p<=n;p++){if(prime[p]==true)for(int i=p*p;i<=n;i+=p)prime[i]=false;}prime[0]=false;prime[1]=false;}
//------------------------------------------------------------------------------------------------------------------------//
void solve(){
ll n,k;
cin>>n;
cout<<n<<" ";
while(n!=1){
if(n%2==0){
n=n/2;
cout<<n<<" ";
}
else{
n=n*3+1;
cout<<n<<" ";
}
}
}
signed main()
{
ishu
ll t = 1;
// cin>>t;
for(ll i = 1 ;i<=t; ++i){
//cout << "Case #"<<i<<": ";
solve();
}
return 0;
}