From 19bb82f44e8da0ab854f93248a8fe72d430b46e4 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Thu, 13 Feb 2025 15:11:28 -0700 Subject: 1617. bit strings --- introductory_problems/bit_strings.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 introductory_problems/bit_strings.cpp (limited to 'introductory_problems/bit_strings.cpp') diff --git a/introductory_problems/bit_strings.cpp b/introductory_problems/bit_strings.cpp new file mode 100644 index 0000000..84acfea --- /dev/null +++ b/introductory_problems/bit_strings.cpp @@ -0,0 +1,21 @@ +// 1617. Bit Strings +#include + +const int mod = 1e9 + 7; + +long long fast_pow2(int x) { + long long res = 1, y = 2; + while (x) { + if (x & 1) + res = (res * y) % mod; + y = (y * y) % mod; + x >>= 1; + } + return res; +} + +int main() { + static int n; + scanf("%d", &n); + printf("%lld\n", fast_pow2(n)); +} -- cgit v1.2.3