From c02795b43eb076a8be65782dc178a00a51f99396 Mon Sep 17 00:00:00 2001 From: Arham Javed <101502781+Arham07@users.noreply.github.com> Date: Mon, 20 Oct 2025 03:16:36 -0700 Subject: [PATCH 1/3] Add solution for Counting Bits #107 --- Counting bits.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Counting bits.cpp diff --git a/Counting bits.cpp b/Counting bits.cpp new file mode 100644 index 0000000..3140a06 --- /dev/null +++ b/Counting bits.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; + +long long countOnes(long long n) { +long long count = 0; +for (long long i = 0; (1LL << i) <= n; i++) { +long long cycle_len = 1LL << (i + 1); +long long full_cycles = (n + 1) / cycle_len; +count += full_cycles * (1LL << i); + +``` + long long remainder = (n + 1) % cycle_len; + count += max(0LL, remainder - (1LL << i)); +} +return count; +``` + +} + +int main() { +ios::sync_with_stdio(false); +cin.tie(nullptr); + +``` +long long n; +cin >> n; +cout << countOnes(n) << "\n"; +return 0; +``` + +} From b25ee9689f6e7544a84a326df761d6ae8ba8bff0 Mon Sep 17 00:00:00 2001 From: Arham Javed <101502781+Arham07@users.noreply.github.com> Date: Mon, 20 Oct 2025 03:29:59 -0700 Subject: [PATCH 2/3] Add solution for Counting Towers #112 --- 3_dp/Counting Towers.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 3_dp/Counting Towers.cpp diff --git a/3_dp/Counting Towers.cpp b/3_dp/Counting Towers.cpp new file mode 100644 index 0000000..5abe338 --- /dev/null +++ b/3_dp/Counting Towers.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; +const long long MOD = 1e9 + 7; + +int main() { + ios::sync_with_stdio(false); + cin.tie(nullptr); + + int t; + cin >> t; + + const int MAXN = 1e6; + vector dpA(MAXN + 1), dpB(MAXN + 1); + dpA[1] = dpB[1] = 1; + + for (int i = 2; i <= MAXN; i++) { + dpA[i] = (2 * dpA[i - 1] + dpB[i - 1]) % MOD; + dpB[i] = (dpA[i - 1] + 4 * dpB[i - 1]) % MOD; + } + + while (t--) { + int n; + cin >> n; + cout << (dpA[n] + dpB[n]) % MOD << "\n"; + } +} From 3ebcabe03c13e532101a77b20b7946d7faab3aa3 Mon Sep 17 00:00:00 2001 From: Arham Javed <101502781+Arham07@users.noreply.github.com> Date: Mon, 20 Oct 2025 03:30:31 -0700 Subject: [PATCH 3/3] Fix formatting issues in Counting Towers.cpp --- 3_dp/Counting Towers.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/3_dp/Counting Towers.cpp b/3_dp/Counting Towers.cpp index 5abe338..e1a1b04 100644 --- a/3_dp/Counting Towers.cpp +++ b/3_dp/Counting Towers.cpp @@ -8,7 +8,6 @@ int main() { int t; cin >> t; - const int MAXN = 1e6; vector dpA(MAXN + 1), dpB(MAXN + 1); dpA[1] = dpB[1] = 1;