From be030b74805f245c8618c77b03e76f16b3fc945a Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Tue, 17 Dec 2024 13:18:18 -0700 Subject: 1608. weird algorithm --- introductory_problems/weird_algorithm.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 introductory_problems/weird_algorithm.cpp (limited to 'introductory_problems/weird_algorithm.cpp') diff --git a/introductory_problems/weird_algorithm.cpp b/introductory_problems/weird_algorithm.cpp new file mode 100644 index 0000000..d8f42c3 --- /dev/null +++ b/introductory_problems/weird_algorithm.cpp @@ -0,0 +1,13 @@ +// 1608. Weird Algorithm +#include +using namespace std; + +int main() { + long long num; + scanf("%lld", &num); + while (num > 1) { + printf("%lld ", num); + num = num & 1 ? 3 * num + 1 : num / 2; + } + printf("1\n"); +} -- cgit v1.2.3