Kyopro Library
読み取り中…
検索中…
一致する文字列を見つけられません
arithmetic_sum.hpp
[詳解]
1
#
include
"../../kyopro_library/template.hpp"
2
3
/// @brief 等差数列
4
struct
ArithmeticProgression
{
5
ll
start
=
INFL
,
goal
=
INFL
,
step
=
INFL
,
length
=
INFL
;
6
7
/// @brief 初項、公差、末項、項数のうち、足りない情報を計算する
8
void
normalize
() {
9
int
undef_cnt=0;
10
if
(
start
==
INFL
) undef_cnt++;
11
if
(
goal
==
INFL
) undef_cnt++;
12
if
(
step
==
INFL
) undef_cnt++;
13
if
(
length
==
INFL
) undef_cnt++;
14
assert(undef_cnt<=1);
15
if
(
goal
==
INFL
)
goal
=
start
+(
length
-1)*
step
;
16
else
if
(
start
==
INFL
)
start
=
goal
-(
length
-1)*
step
;
17
else
if
(
step
==
INFL
)
step
=(
start
==
goal
)?0:(
goal
-
start
)/(
length
-1);
18
else
if
(
length
==
INFL
) {
19
assert(
step
!=0);
20
length
=(
goal
-
start
)/
step
+1;
21
}
22
}
23
};
24
25
/// @brief 等差数列の和を返す
26
ll
ArithmeticSum
(
ArithmeticProgression
ap) {
27
ap
.
normalize
(
)
;
28
return
(ap
.
start
+ap
.
goal
)*ap
.
length
/2;
29
}
ArithmeticSum
ll ArithmeticSum(ArithmeticProgression ap)
等差数列の和を返す
Definition
arithmetic_sum.hpp:26
ArithmeticProgression
等差数列
Definition
arithmetic_sum.hpp:4
ArithmeticProgression::start
ll start
Definition
arithmetic_sum.hpp:5
ArithmeticProgression::normalize
void normalize()
初項、公差、末項、項数のうち、足りない情報を計算する
Definition
arithmetic_sum.hpp:8
ArithmeticProgression::step
ll step
Definition
arithmetic_sum.hpp:5
ArithmeticProgression::goal
ll goal
Definition
arithmetic_sum.hpp:5
ArithmeticProgression::length
ll length
Definition
arithmetic_sum.hpp:5
INFL
const ll INFL
Definition
template.hpp:13
others
arithmetic_sum.hpp
構築:
1.13.2