You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
576 B
23 lines
576 B
fn main() { |
|
{ |
|
// SOLUTION 1 |
|
let mut sum_1 = 0; |
|
let mut sum_a = 0; |
|
for i in 0..=100 { |
|
sum_1 += i; |
|
sum_a += i * i; |
|
} |
|
let diff = sum_1 * sum_1 - sum_a; |
|
println!("sum_1: {}", sum_1 * sum_1); |
|
println!("sum_a: {}", sum_a); |
|
println!("solution1: {}", diff); |
|
} |
|
|
|
{ |
|
// SOLUTION 2 |
|
let n = 100; |
|
let solution_2 = ( (n * (n + 1) ) / 2) * ( (n * (n + 1) ) / 2 ) - ( (n * (n + 1) * (2 * n + 1)) / 6 ); |
|
println!("solution2: {}", solution_2); |
|
} |
|
|
|
}
|
|
|