cses

solution to cses exercise problems
git clone git://git.superpozycja.net/cses
Log | Files | Refs | README

commit a497a16a5e26af7825ff2b82c0cea76d931d7737
parent 069481b72d549f34f6455f1af69beed9dee6145d
Author: superpozycja <anna@superpozycja.net>
Date:   Wed, 23 Oct 2024 21:06:23 +0200

add chal 1

Diffstat:
Aintro/weird_algorithm.cpp | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/intro/weird_algorithm.cpp b/intro/weird_algorithm.cpp @@ -0,0 +1,22 @@ +#include <bits/stdc++.h> + +using namespace std; + +void solve() +{ + long n; + cin >> n; + while (n != 1) { + cout << n << " "; + if (n % 2) + n = 3 * n + 1; + else + n >>= 1; + } + cout << "1\n"; +} + +int main() +{ + solve(); +}