first 7 Introductory problems
This commit is contained in:
23
CSES - CSES Problem Set/Weird_Algorithm.cpp
Normal file
23
CSES - CSES Problem Set/Weird_Algorithm.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
// Weird Algorithm
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
typedef long long ll;
|
||||
|
||||
|
||||
int main() {
|
||||
ll n;
|
||||
cin >> n;
|
||||
while (n != 1) {
|
||||
cout << n << " ";
|
||||
if (n & 1) {
|
||||
n *= 3;
|
||||
n++;
|
||||
} else {
|
||||
n /= 2;
|
||||
}
|
||||
}
|
||||
cout << n << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user