Masha and geometric depression
传送门
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b b b defined by two integers b 1 b_{1} b1and q q q . Remind that a geometric progression is a sequence of integers b 1 , b 2 , b 3 , . . . b_{1},b_{2},b_{3},... b1,b2,b3,... , where for each i > 1 i>1 i>1 the respective term satisfies the condition b i = b i − 1 ⋅ q b_{i}=b_{i-1}·q bi=bi−1⋅q , where q q q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b 1 b_{1} b1 and q q q can equal 0 0 0 . Also, Dvastan gave Masha m m m “bad” integers a 1 , a 2 , . . . , a m a_{1},a_{2},...,a_{m} a1,a2,...,am , and an integer l l l .
Masha writes all progression terms one by one onto the board (including repetitive) while condition ∣ b i ∣ < = l |b_{i}|<=l ∣bi∣<=l is satisfied ( ∣ x ∣ |x| ∣x∣ means absolute value of x x 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 b_{1} b1 , q q q , l l l , m m m (- 1 0 9 < = b 1 , q < = 1 0 9 10^{9}<=b_{1},q<=10^{9} 109<=

最低0.47元/天 解锁文章
196

被折叠的 条评论
为什么被折叠?



