Website Summary Files Commits Branches @commit @diff @stats
path: root / Week05 / Exercise09.cpp
blob: adcd5b1e19faada68f74697bd29d2e358dd53040 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>

int main()
{
    double z;
    unsigned int n;
    std::cin >> z >> n;

    double base = z - 1;
    double sum = 0;

    for (unsigned int i = 1; i <= n; i++) {
        double to_power = 1;

        for (unsigned j = 1; j <= i; j++) {
            to_power *= base;
        }

        sum += ((i + 1) % 2 ? -1.0 : 1.0) * to_power / i;
    }

    std::cout << sum << std::endl;

    return 0;
}