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

Random Function

Time Limit: 12000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 302    Accepted Submission(s): 50


Problem Description
Cover is an admin of HOJ, MUT is coming and he needs to generate passwords for every team of MUT. Thus he needs a pesudo-random number generator.

As we know, random numbers are usually gernerated by a random number table and a random seed. The random table is an large array. Using random seed to calculate a subscript, we can use the corresponding number in the talbe as a pesudo-random number.

But Cover is a geek and he won't do this as others did. He uses a circle array of length N as random table and three numbers ( a, b, c) as random seed. The random nubmer is defined as the product of table[a], table[(a+b-1)%N+1], table[(a+2b-1)%N+1] ... table[c] ( see Sample Input for more details). Of course this product P may be too large, so Cover use P % 1000000007 as the result.

Now it's your task, given the table and a query( a, b, c), help Cover find out the pesudo-random number.
 

Input
Multiple test cases, at most 20. Process to the end of the file.

The first line of input contains three numbers, N, Q, (1 ¡Ü N ¡Ü 50000, 1 ¡Ü Q ¡Ü 50000) descripting the length of the circle array, the number of queries, and M mentioned above. The second line contains N positive integers less than 10^9, denotes the (1..N)th numbers of the circle array. Then comes Q lines, each line contains three number, means a query of a, b, c ( 1 ¡Ü a, b, c ¡Ü N). It's guaranteed that there's an interger i makes c = a + b * i or c + N = a + b * i;
 

Output
Print Q lines for each test case, one number per line, which is the pesudo-random number.
 

Sample Input
6 5 1 2 3 4 5 6 1 1 6 1 3 1 1 3 4 2 4 6 3 5 2
 

Sample Output
720 1 4 12 6
 

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 21:10:06, Gzip enabled