Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/ishorasi-almashinuvchi-geometrik-qator

Alternating geometric series

Easy 1000 ms 64 MB 28%
Share

A real number $a$ and a positive integer $N$ are given. Compute the sum:

$$S = 1 - a + a^{2} - a^{3} + \dots + (-1)^{N} * a^{N}$$

An alternating sum of powers

Input

One line with a real number $a$ and a positive integer $N$.

Output

One number — $S$, with exactly 2 digits after the decimal point (for example, -5.00).

Note

$0 \lt a \le 10$
$a$ has at most $1$ digit after the decimal point
$1 \le N \le 10$

Examples

Input #1
2 3
Output #1
-5.00
Input #2
3 2
Output #2
7.00

Sign in to submit a solution

Signing up is free and takes a minute.