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.
24 lines
576 B
24 lines
576 B
2 years ago
|
fn main() {
|
||
|
{
|
||
|
// SOLUTION 1
|
||
|
let mut sum_1 = 0;
|
||
|
let mut sum_a = 0;
|
||
2 years ago
|
for i in 0..=100 {
|
||
2 years ago
|
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
|
||
2 years ago
|
let n = 100;
|
||
2 years ago
|
let solution_2 = ( (n * (n + 1) ) / 2) * ( (n * (n + 1) ) / 2 ) - ( (n * (n + 1) * (2 * n + 1)) / 6 );
|
||
|
println!("solution2: {}", solution_2);
|
||
|
}
|
||
|
|
||
|
}
|