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

Linear recursive sequence

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 654    Accepted Submission(s): 224


Problem Description
A well-known linear recursive sequence f(n) is defined as follows.

For k¡Ü0, f(k)=1
For k¡Ý1, f(k)=a*f(k - p)+b*f(k - q).

Given n,a,b,p,q, find the value of f(n) modulo 119.
 

Input
The input consists of several tests. For each tests:

5 integers n,a,b,p,q (1¡Ün¡Ü109,0¡Üa,b¡Ü109,1¡Üp<q¡Ü104).
 

Output
For each tests:

A single integer f(n).
 

Sample Input
1 1 1 1 2 1000000000 1 2 3 4
 

Sample Output
2 [b]100[/b]
 

Author
Xiaoxu Guo (ftiasch)
 

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-09-28 06:13:04, Gzip enabled