51Nod1363,1190 and least common multiple of V1, V2

And the least common multiple of 1363

1.5 seconds 131,072.0 KB 160 points six questions
given a n, 1-n find this number n, and with the least common multiple of n.
For example: n = 6,1,2,3,4,5,6 least common multiple of the same, respectively 6,6,6,12,30,6 6, 66 = together.
As a result of large output of 1,000,000,007 result Mod.

Entry

Line 1: a number T, the number indicates the number of tests later used as an input. (1 <= T <= 50000 )
of 2 - T + 1 rows: T Number A I

Export

Total line T, and the output corresponding to the least common multiple of

SAMPLE INPUT

3
5
6
9

Sample Output

55
66
279



This problem with SPOJ LCMsum is the same, but the range of data is not the same, so pushed to the back of the operation is not the same.

Star_Feel solution to a problem of

Original title corresponds request \ (\ sum_ {i = 1 } ^ {n} \ frac {i * n} {gcd (i, n)} \)

First Enumeration \ (D = \ GCD (I, n-) \) , then the resulting simplification
\ [n * \ sum_ {d | n} \ sum_ {i = 1} ^ {\ frac {n} {d}} i [\ gcd (i, \
frac {n} {d}) = 1] \] corresponds seeking \ (1 \) to the \ (n-1 \) in the \ (n-\) prime numbers and , set \ (Y <X \) , if the \ (\ GCD (Y, X) =. 1 \) , then the \ (\ GCD (XY, X) =. 1 \) , two formulas contribution is \ (X \) the

So \ (1 \) to (n-1 \) \ in the \ (n-\) prime number and is \ (\ FRAC {\ Phi (n-) * n-} {2} \) , special, If \ (n-1,2 = \) , and is the \ (1 \)

Then the original formula is equal to
\ [n * \ sum_ {d | n and d is not n} \ frac {\ frac { n} {d} * \ phi (\ frac {n} {d})} {2} + 1 \]
then simplified to obtain
\ [n + \ frac {n } {2} \ sum_ {d | n and d> 1} d * phi (
d) \] Thus, this equation becomes \ (O (\ {} n-sqrt) \) , but a plurality of sets of data will still timeout

We will actually \ (\ n-) prime factor decomposition \ (n = \ prod_ {i = 1} ^ {x} p [i] ^ a [i] \)

Since \ (p [i] \) pairwise substance, it can be converted to
\ [n + \ prod_ {i = 1} ^ {x} \ sum_ {j = 0} ^ {a [i]} \ phi (p [i] ^ j) * p
[i] ^ j \] Depending on the nature of the Euler function can be
\ [n + \ prod_ {i = 1} ^ {x} 1+ \ sum_ {j = 1} ^ {a [ i]} (p [i]
-1) * p [i] ^ {2j-1} \] then obtained according to the geometric series summation formula
\ [n + \ prod_ {i = 1} ^ {x} 1+ ( p [i] -1) * \ frac {p [i] ^ {2 * a [i] +1} -p [i]} {p [i] ^ 2-1} \\ = n + \ prod_ {i = 1} ^ {x} 1+
\ frac {p [i] ^ {2 * a [i] +1} -p [i]} {p [i] +1} \] then wire mesh acceleration prime prime factor decomposition can be passed, remember the last treatment \ (1 \) case

1190 and the least common multiple of V2

2 given the number of a, b, seeking LCM (a, b) + LCM (a + 1, b) + .. + LCM (b, b).
For example: a = 1, b = 6,1,2,3,4,5,6 least common multiple of the same, respectively 6,6,6,12,30,6 6, 66 = together.
As a result may be large, the output result Mod 10 ^ 9 + 7. (Test data is random data, no special configuration deceptive Test)

Entry

Line 1: a number T, the number indicates the number of tests later used as an input. (1 <= T <= 50000 )
of 2 - T + 1 rows: the number of each line 2 a, b, separated by a space intermediate (1 <= a <= b <= 10 ^ 9)

Export

T co row, the result output corresponding to the sum of the least common multiple of Mod 10 ^ 9 + 7 in.

SAMPLE INPUT

3
1 6
10 15
41 90

Sample Output

66
675
139860

Cold_Chair solution to a problem of

\[ ans = \sum_{i = a}^b \textrm{lcm}(i) \\ = b*\sum_{d | b} \sum_{i = \lfloor{ {a} \over {d}}\rfloor}^{\lceil{ {b} \over {d}}\rceil} i * [\gcd(i, { {b} \over {d}}) = 1] \\ = b*\sum_{d | b} \sum_{i = \lfloor{ {a} \over {d}}\rfloor}^{\lceil{ {b} \over {d}}\rceil} i * \sum_{d' | \gcd(i, { {b} \over {d}})} μ(d') \\ = b*\sum_{d | b} \sum_{d' | { {b} \over {d}}} μ(d') * d' * \sum_{i = \lfloor{ {b} \over {d }}\rfloor}^{\lceil{ {a} \over {d}}\rceil}i*[d' | i] \\ = b*\sum_{d | b} \sum_{d' | { {b} \over {d}}} μ(d') * d' * \sum_{i = \lfloor{ {b} \over {d*d' }}\rfloor}^{\lceil{ {a} \over {d * d'}}\rceil}i \\ = b*\sum_{d | b} \sum_{d' | { {b} \over {d}}} μ(d') * d' * (\lfloor{ {b} \over {d*d' }}\rfloor - \lceil{ {a} \over {d * d'}}\rceil + 1) * (\lfloor{ {b} \over {d*d' }}\rfloor + \lceil{ {a} \over {d * d'}}\rceil) / 2 \]

Provided $ T = D * D '$
\ [= B * \ sum_ {T | B} (\ lfloor {{B} \ over {T}} \ rfloor - \ lceil {{A} \ over {T}} \ rceil + 1) * (\ lfloor {{b} \ over {T}} \ rfloor + \ lceil {{a} \ over {T}} \ rceil) / 2 * \ sum_ {d | T} μ (d) * d \]
we look at the $ \ sum_ {d | T} μ (d) * d $
Dirichlet convolution to do so much, easily available:
if \ (T = \ prod {p_i ^ {q_i}} \) , then
\ [\ sum_ {d | T } μ (d) * d = \ prod {1-p_i} \]

Guess you like

Origin www.cnblogs.com/autoint/p/11104435.html