CF789B.Masha and geometric depression
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
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 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.
玛莎非常热爱代数。在上一节课上,她严厉的老师达瓦斯坦给她布置了一道新习题。
给定一个由两个整数 b1 和 q 定义的等比数列 b。请回忆:等比数列是一个整数序列 b1,b2,b3,…,其中对每个 i>1,对应项满足条件 bi=bi−1⋅q,其中 q 称为该数列的公比。乌日利亚的等比数列很特殊:b1 和 q 均可为 0。此外,达瓦斯坦还给了玛莎 m 个“坏”整数 a1,a2,…,am,以及一个整数 l。
玛莎将等比数列的各项依次(包括重复项)写在黑板上,只要满足条件 ∣bi∣≤l(∣x∣ 表示 x 的绝对值)。但有一个例外:若某一项等于某个“坏”整数,则玛莎跳过该项(不写在黑板上),直接进入下一项。
然而,这堂课即将结束,因此玛莎需要计算最终写在黑板上的整数个数。为了避免陷入沮丧,玛莎请你帮忙:请帮她计算她将写出多少个数字;若她需要写出无穷多个数字,则输出 inf。
输入格式
The first line of input contains four integers _b_1, q, l, m (-109 ≤ _b_1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — 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 (-109 ≤ a__i ≤ 109) — numbers that will never be written on the board.
输入的第一行包含四个整数 b1、q、l、m(−109≤b1,q≤109,1≤l≤109,1≤m≤105),分别表示等比数列的首项、公比、可写在黑板上的数的绝对值上限,以及“坏”整数的个数。
第二行包含 m 个互不相同的整数 a1,a2,…,am(−109≤ai≤109),表示永远不能写在黑板上的数字。
输出格式
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.
输出唯一的整数,即如果该数列项数有限,则为将写在黑板上的等差数列项数;否则输出 inf(不带引号)。
输入输出样例
输入#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, 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.
在第一个样例中,玛莎将写下整数 3,12,24。等差数列的项 6 将被跳过,因为它是“坏”整数。大于 24 的项不会被写下,因为它们的绝对值超过了 l。
在第二个样例中,玛莎不会写下任何数字,因为所有项都等于 123,而 123 是一个“坏”整数。
在第三个样例中,玛莎将无限次写下整数 123。
输入解题思路,AI测评打分。不知道怎么写?