F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

The More The Better

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3747    Accepted Submission(s): 987


Problem Description
Given an sequence of numbers {X1, X2, ... , Xn}, where Xk = (A * k + B) % mod. Your task is to find the maximum sub sequence {Y1, Y2, ... , Ym} where every pair of (Yi, Yj) satisfies Yi + Yj <= L (1 ¡Ü i < j ¡Ü m), and every Yi <= L (1 ¡Ü i ¡Ü m ).
Now given n, L, A, B and mod, your task is to figure out the maximum m described above.
 

Input
Multiple test cases, process to the end of input. Every test case has a single line. A line of 5 integers: n, L, A, B and mod. (1 ¡Ü n ¡Ü 2*107, 1 ¡Ü L ¡Ü 2*109, 1 ¡Ü A, B, mod ¡Ü 109)
 

Output
For each case, output m in one line.
 

Sample Input
1 8 2 3 6 5 8 2 3 6
 

Sample Output
1 4
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 05:25:56, Gzip enabled