pub fn arithmetic_series<T: Int>(a: T, n: T, d: T) -> Option<T>
Expand description

初項 a, 項数 n, 公差 d の等差数列の和を求めます。

Panics

if n is negative.

Examples

use arithmetic_series::arithmetic_series;

// 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10
assert_eq!(arithmetic_series(1, 10, 1), Some(55));
// 1 + 3 + 5 + 7 + 9
assert_eq!(arithmetic_series(1, 5, 2), Some(25));
// 5 + 2 + (-1) + (-4) + (-7) + (-10)
assert_eq!(arithmetic_series(5, 6, -3), Some(-15));