B - Sum of Geometric Series Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

正整数 N, M が与えられます。

X = \displaystyle\sum_{i = 0}^{M} N^i とします。X \leq 10^9 のときは X の値を、X > 10^9 のときは文字列 inf を出力してください。

制約

  • 1 \leq N \leq 10^9
  • 1 \leq M \leq 100
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N M

出力

問題文の指示に従って X の値あるいは inf を出力せよ。


入力例 1

7 3

出力例 1

400

X = 1 + 7 + 49 + 343 = 400 です。400 \leq 10^9 であるため 400 を出力します。


入力例 2

1000000 2

出力例 2

inf

X = 1000001000001 > 10^9 であるため、inf を出力します。


入力例 3

999999999 1

出力例 3

1000000000

入力例 4

998244353 99

出力例 4

inf

Score : 200 points

Problem Statement

You are given two positive integers N and M.

Let X = \displaystyle\sum_{i = 0}^{M} N^i. If X \leq 10^9, print the value of X. If X > 10^9, print inf.

Constraints

  • 1 \leq N \leq 10^9
  • 1 \leq M \leq 100
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N M

Output

Print the value of X or inf as specified by the problem statement.


Sample Input 1

7 3

Sample Output 1

400

X = 1 + 7 + 49 + 343 = 400. Since 400 \leq 10^9, print 400.


Sample Input 2

1000000 2

Sample Output 2

inf

X = 1000001000001 > 10^9, so print inf.


Sample Input 3

999999999 1

Sample Output 3

1000000000

Sample Input 4

998244353 99

Sample Output 4

inf