Coin de Gamma
2 years ago
1 changed files with 23 additions and 0 deletions
@ -0,0 +1,23 @@ |
|||||||
|
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 = 99; |
||||||
|
let solution_2 = ( (n * (n + 1) ) / 2) * ( (n * (n + 1) ) / 2 ) - ( (n * (n + 1) * (2 * n + 1)) / 6 ); |
||||||
|
println!("solution2: {}", solution_2); |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue