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

Touma Kazusa's function

Time Limit: 15000/15000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 313    Accepted Submission(s): 64


Problem Description
$Touma Kazusa$ is dating with $Kitahara Haruki$. To test if $Haruki$ is a skilled man, $Kazusa$ created a function which called $Kazusa$ $function $. Its expression is as follows:

$S(l,r) = \sum_{i=l}^{r}\sum_{j=l}^{r}\varphi(gcd(a_i,a_j))lcm(a_i,a_j)$ .$l$ and $r$ are the left and right endpoints of an interval of sequence $a$, respectively.

However, because this function is really easy for $Haruki$ and $Haruki$ told $Kazusa$ the answer quickly. So $Kazusa$ strengthened the problem.

Now, $Kazusa$ will gives $Haruki$ a sequence $a$ and $q$ intervals, and for each interval, $Haruki$ should calculate $S(l,r)$.$Haruki$ still thinks it's easy for him, but he just want to date with $Kazusa$, So this problem should solved by you.

Because the value of $S(l,r)$ maybe too large, you only need output $S(l,r)$ $mod$ $2^{32}$
 

Input
There are multiple test cases. The first line of the input contain an integer $T(1 \leq T \leq 100)$, indicating the number of test cases. For each test case:

First line contains two positive integers $n(1 \leq n \leq 1e5)$ and $q(1 \leq q \leq 1e5)$ which are separated by spaces, denoting the length of sequence $a$ and the number of interval.

Second line contains $n$ positive integers $a_1$,$a_2$,$a_3$,...,$a_n$$(1\leq a_i\leq 1e7)$.

Following $q$ lines, each line contain two integers $l, r$.$(1 \leq l \leq r \leq n)$

It is guaranteed that $\sum_{n} \leq 3e5$ and $\sum_{q} \leq 3e5$, and at most two cases $n = 1e5$. When $n = 1e5$,it is guaranteed that all $a_i$ are generated randomly.
 

Output
Output $q$ lines, each line is an integer, representing the value of $S(l,r)$ $mod$ $2^{32}$.
 

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

Sample Output
199
 

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-04-19 10:49:42, Gzip enabled