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

Function

Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 5464    Accepted Submission(s): 1679


Problem Description
The shorter, the simpler. With this problem, you should be convinced of this truth.
  
  You are given an array $A$ of $N$ postive integers, and $M$ queries in the form $(l, r)$. A function $F(l, r)\ (1\le l \le r \le N)$ is defined as:
$F(l,r)=\left\{\begin{matrix}
A_{l}&l=r; \\
F(l, r-1)\ mod A_{r}& l<r.
\end{matrix}\right.$
You job is to calculate $F(l, r)$, for each query $(l, r)$.
 

Input
There are multiple test cases.
  
  The first line of input contains a integer $T$, indicating number of test cases, and $T$ test cases follow.
  
  For each test case, the first line contains an integer $N (1\le N \le 100000)$.
  The second line contains $N$ space-separated positive integers: $A_{1},\dots, A_{N}\ (0\le A_{i} \le 10^9)$.
  The third line contains an integer $M$ denoting the number of queries.
  The following $M$ lines each contain two integers $l, r \ (1 \le l \le r \le N)$, representing a query.
 

Output
For each query$ (l, r)$, output $F(l, r)$ on one line.
 

Sample Input
1 3 2 3 3 1 1 3
 

Sample Output
2
 

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 13:15:15, Gzip enabled