CF789B.Masha and geometric depression

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

You are given geometric progression bb defined by two integers b1b_{1} and qq . Remind that a geometric progression is a sequence of integers b1,b2,b3,...b_{1},b_{2},b_{3},... , where for each i>1 the respective term satisfies the condition bi=bi1qb_{i}=b_{i-1}·q , where qq is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b1b_{1} and qq can equal 00 . Also, Dvastan gave Masha mm "bad" integers a1,a2,...,ama_{1},a_{2},...,a_{m} , and an integer ll .

Masha writes all progression terms one by one onto the board (including repetitive) while condition bi<=l|b_{i}|<=l is satisfied ( x|x| means absolute value of xx ). 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.

输入格式

The first line of input contains four integers b1b_{1} , qq , ll , mm (- 109<=b1,q<=10910^{9}<=b_{1},q<=10^{9} , 1<=l<=1091<=l<=10^{9} , 1<=m<=1051<=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 mm distinct integers a1,a2,...,ama_{1},a_{2},...,a_{m} (- 109<=ai<=109)10^{9}<=a_{i}<=10^{9}) — numbers that will never be written on the board.

输出格式

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.

输入输出样例

  • 输入#1

    3 2 30 4
    6 14 25 48
    

    输出#1

    3
  • 输入#2

    123 1 2143435 4
    123 11 -5453 141245
    

    输出#2

    0
  • 输入#3

    123 1 2143435 4
    54343 -13 6 124
    

    输出#3

    inf

说明/提示

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

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

In the third case, Masha will write infinitely integers 123123 .

首页