Benny and Balls
Practice
2.6 (17 votes)
Basic programming
Implementation
Medium
Problem
34% Success 2287 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
In this problem Benny is looking for your help as usual.
There are N baskets, which are numbered from 0 to N - 1.
In each moment of time exactly, starting with t = 1, one ball appears in xi-th basket, where xi = (a * x(i-1) + b) % N.
The bottom of the i-th basket opens when there is not less than the p[i] balls in it, all the balls fall out of the basket, and then the bottom of the basket is closed again.
How many times baskets' bottoms will open to the T-th moment of time?
Input
The first line containts Q - the amount of test cases.
Each test case consist of three lines:
First line contains N
Second line contains N numbers p[i]
Third line contains x1 , a, b, t
xi = (a * xi-1 + b) % N;
Output
Q lines - answers for each case
Constraints
- 1 ≤ N ≤ 105
- 1 ≤ Q ≤ 10
- 1 ≤ p[i] ≤ 105
- 1 ≤ A, B ≤ 109
- 0 ≤ X < N
- 0 ≤ t < 106
Submissions
Please login to view your submissions
Similar Problems
Points:30
3 votes
Tags:
Binary search treeCombinatoricsGraphsMedium
Points:30
9 votes
Tags:
Basic ProgrammingBasics of ImplementationImplementationMediumSortingTwo pointer
3.AABBAAC
Points:30
17 votes
Tags:
ApprovedImplementationMediumOpenString Manipulation
Editorial