From 08cf60126aaab6892f283eefbe7db5c9c5f3b94f Mon Sep 17 00:00:00 2001 From: Muhammad Nauman Raza Date: Sat, 1 Feb 2025 22:05:07 +0000 Subject: [PATCH] solutions: 598A --- solutions/rust/src/bin/598A.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 solutions/rust/src/bin/598A.rs diff --git a/solutions/rust/src/bin/598A.rs b/solutions/rust/src/bin/598A.rs new file mode 100644 index 0000000..e5d555f --- /dev/null +++ b/solutions/rust/src/bin/598A.rs @@ -0,0 +1,29 @@ +use std::io; + +fn main() { + let mut s = String::new(); + io::stdin().read_line(&mut s).unwrap(); + + let t: i64 = s.trim().parse().unwrap(); + + let mut total = 0; + + for _ in 0..t { + let mut s = String::new(); + io::stdin().read_line(&mut s).unwrap(); + + let n: i64 = s.trim().parse().unwrap(); + + total += n*(n+1)/2; + + let mut exponent = 0; + while 2_i64.pow(exponent) <= n { + exponent += 1; + total -= 2_i64.pow(exponent); + } + + println!("{}", total); + total = 0; + } + +}