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

DZY Loves Math

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 606    Accepted Submission(s): 197


Problem Description
DZY loves math since he was very young. One day he meets this problem:

Calculate $\sum_{1\le i\le n} \sum_{1\le j \le m} \gcd(i \text{ AND } j, i \text{ OR } j)$ĄŁ$\gcd(a,b)$ means the greatest common divisor of $a,b$. When $a\neq 0$, define $\gcd(0,a)=a$ĄŁAND, OR means bitwise and, or operation.

DZY says he has been tired of such kind of problems, so he leaves it to you.
 

Input
First line contains $t$, meaning there are $t$ testcases.

$t$ testcases follow. Each testcase has a line containing two integers $n,m$.

($1\le t \le 3,1\le n,m \le 15000$. There are at most $2$ testcases such that $\max\{n,m\}>2000$. There are at most $1$ testcase such that $\max\{n,m\}>8000$)
 

Output
Output the answer in one line for each testcase.
 

Sample Input
3 3 5 30 50 210 15000
 

Sample Output
43 15467 2660805398
 

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-05-02 15:02:32, Gzip enabled