# jzptab

### Output

T行 每行一个整数 表示第i组数据的结果

1

4 5

122

T <= 10000

N, M<=10000000

`c++

# include<bits/stdc++.h>

using namespace std;
const int maxn = 1e7 + 5, maxm = 1e7, mod = 1e8 + 9;
int n, m, cnt, prime[maxn];
long long S[maxn];
bool not_prime[maxn];

inline void prepare()
{
S[1] = 1;
for(int i = 2; i <= maxm; ++i){
if(!not_prime[i]){
prime[++cnt] = i; S[i] = (i - (long long)i * i) % mod;
}
for(int j = 1; prime[j] * i <= maxm; ++j){
not_prime[prime[j] * i] = true;
if(i % prime[j] == 0){
S[prime[j] * i] = S[i] * prime[j] % mod;
break;
}
S[prime[j] * i] = S[prime[j]] * S[i] % mod;
}
}
for(int i = 1; i <= maxm; ++i) S[i] = (S[i] + S[i - 1]) % mod;
}

inline long long sum(long long a, long long b){
long long A = ((a + 1) * a >> 1) % mod, B = ((b + 1) * b >> 1) % mod;
return A * B % mod;
}

inline long long workk()
{
int last; long long ans = 0;
for(int D = 1; D <= n; D = last + 1){
last = min(n / (n / D), m / (m / D));
ans = (ans + sum(n / D, m / D) * (S[last] - S[D - 1]) % mod) % mod;
}
return (ans + mod) % mod;
}

int main()
{
prepare();
int T; scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &m);
if(n > m) swap(n, m);
printf("%lld\n", workk());
}
return 0;
}

posted @ 2018-06-08 15:42  沛霖  阅读(89)  评论(0编辑  收藏  举报