A little math of


A small number of recently began to study the topic, and this time he readily write out a formula,

 

But he found that he was not likely to calculate this formula, you can tell him the results, the answer may be relatively large, please die on 1000000007.

Enter a description:

Line two positive integers n, m row two positive integers n, m a row two th positive integer number n- , m

Output Description:

A line output line a represents an integer of integer output a row a th integer number table shows output the junction results
Example 1

Entry

copy
2 2

Export

copy
7

Notes 1 ≦ n, m≤1e61 \ n-Leq, m \ Leq 1e6 . 1 n- title meaning: Given two numbers, n, m; seeking (1 ~ n) (1 ~ m) of the gcd (i, j) sum of square


Ideas: Simple violence certainly timeout,
see the greatest common divisor of two numbers, we turn seek the greatest possible number of conventions begin progressively decreasing from min (n, m)
from min (n, m) ~ 1
so that p = min (n, m),
then n p which has a multiple of n / p, namely the presence of the divisor p n / p number
for the same purposes m;
after again starting from p * 2 all the multiples of p then lost, the rest is about the maximum number is the number of p, i.e., for n, m terms that gcd (n, m) == all combinations of p (n / p) * (m / p);

examples of
n-=. 9, m =. 7;
P =. 7;
GCD (I, J) ==. 7;
F [. 7] =. 1;
GCD (I, J) =. 6;
F [. 6] =. 1;
GCD (I, J) =. 5;
F [. 5] =. 5;
GCD (I, J) =. 4;
F [. 4] = 2;
gcd(i,j)=3;
f[3]=5;
gcd(i,j)=2;
f[2]=9;
f[1]=44;

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 typedef long long ll;
 5 const int N = 1e6+10;
 6 #define mod 1000000007
 7 ll n,m;
 8 ll num;
 9 ll f[N];
10 int main()
11 {
12     scanf("%lld%lld",&n,&m);
13     for(int i = min(n,m); i >=1;i--)
14     {
15         f[i] = (n / i) * (m / i);
16         for(int j = 2 * i; j <= min(n , m); j += i)
17         {
18             f[i] -= f[j];
19         }
20         //cout << f[i]<<' '<<i<<endl;
21         num = (num + f[i] * i % mod * i % mod )%mod;
22     }
23     cout << num <<endl;
24     return 0;
25 }
View Code

 

 
 
 

 

Guess you like

Origin www.cnblogs.com/wangzhe52xia/p/11404406.html