Codeforces Round 407 (Div. 2)
B
Masha and geometric depression
Codeforces
1700
原题
← AC →
翻译中…

Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.

翻译中…

You are given geometric progression $*b*$ defined by two integers $*b*_{1}$ and $*q*$. Remind that a geometric progression is a sequence of integers $*b*_{1}, *b*_{2}, *b*_{3}, ...$, where for each $*i* > 1$ the respective term satisfies the condition $*b*_{*i*} = *b*_{*i* - 1}·*q*$, where $*q*$ is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both $*b*_{1}$ and $*q*$ can equal $0$. Also, Dvastan gave Masha $*m*$ "bad" integers $*a*_{1}, *a*_{2}, ..., *a*_{*m*}$, and an integer $*l*$.

翻译中…

Masha writes all progression terms one by one onto the board (including repetitive) while condition $|*b*_{*i*}| ≤ *l*$ is satisfied ($|*x*|$ means absolute value of $*x*$). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.

翻译中…

But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.

翻译中…

Input

翻译中…

The first line of input contains four integers $*b*_{1}$, $*q*$, $*l*$, $*m*$ (-$10^{9} ≤ *b*_{1}, *q* ≤ 10^{9}$, $1 ≤ *l* ≤ 10^{9}$, $1 ≤ *m* ≤ 10^{5}$) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.

翻译中…

The second line contains $*m*$ distinct integers $*a*_{1}, *a*_{2}, ..., *a*_{*m*}$ (-$10^{9} ≤ *a*_{*i*} ≤ 10^{9})$ — numbers that will never be written on the board.

翻译中…

Output

翻译中…

Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.

翻译中…

Note

翻译中…

In the first sample case, Masha will write integers $3, 12, 24$. Progression term $6$ will be skipped because it is a "bad" integer. Terms bigger than $24$ won't be written because they exceed $*l*$ by absolute value.

翻译中…

In the second case, Masha won't write any number because all terms are equal $123$ and this is a "bad" integer.

翻译中…

In the third case, Masha will write infinitely integers $123$.

翻译中…

样例

Input #1
3 2 30 4
6 14 25 48
Output #1
3
InputCopy OutputCopy
Input #2
123 1 2143435 4
123 11 -5453 141245
Output #2
0
InputCopy OutputCopy
Input #3
123 1 2143435 4
54343 -13 6 124
Output #3
inf
InputCopy OutputCopy
题目信息
题号
789B
时间限制
1 s
内存限制
256 MB
标签
暴力
模拟
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。