Video Reviews - 2
시간 제한4초메모리 제한512 MB
블로거를 정해진 순서로 처리할 때, 관심이 없어도 이미 올라온 리뷰가 a_i개 이상이면 리뷰를 남긴다. m개 이상의 리뷰를 얻기 위해 설득해야 하는 최소 인원을 구한다. 배열은 LCG로 생성되며 길이는 최대 5e7이다.
문제
Easy problem, just binary search the answer. Oh wait...
You
The studio "Lodka Gaming" is engaged in advertising of their new game ".C.O.N.T.E.S.T: Unexpected Behaviour". The studio's marketer is planning to communicate with videobloggers one by one (in the predetermined order, starting from the 1-st and ending with the -th), offering them to record a video review on the game. All people are different and videobloggers are as well, therefore the -th videoblogger will record a review in two cases: either he is interested in this game, or there are already at least video reviews on this game.
The studio wants to have at least video reviews in the Internet. The game designer of "Lodka Gaming" understands these video reviews possibly would not appear by themselves, so he wants to convince some video bloggers that they are actually interested in this game. Which minimal number of videobloggers are needed to be convinced?
입력
The first line contains two integers and () --- the number of videobloggers and the required number of video reviews.
As can be too large, the values will be generated by linear congruential random number generators.
The second line contains two integers and ().
Each of the following lines contains 4 integers , , and (). are prime numbers. All , except the first one, will be generated using these numbers. The first of them will be generated using the formula , the next --- using the formula , and so on. It is guaranteed that the sum of all is .
출력
Output a single integer --- the minimal number of videobloggers who have to be convinced to record a video review on the game in order to achieve at least total video reviews in the Internet.
힌트
In the first sample, .
In the second sample, .