Блог пользователя yyjhzx

Автор yyjhzx, история, 9 лет назад, По-английски

Hi, i'm trying to solve the following problem : Given 1 ≤ m ≤ n ≤ 100000 , calculate:

If n = m is kind of easy, but i can't think of anything for n > m.

PS:I think an solution or anything similar can be squeezed to pass TL , if you have any idea please share :D

  • Проголосовать: нравится
  • +18
  • Проголосовать: не нравится

»
9 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

This can be done by phi function. kind of similar question good explanation link. If you understand that then this is pretty easy

»
9 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +18 Проголосовать: не нравится

dp[i] = number of pairs (a, b) that gcd(a, b) = i. It's very easy to calculate it in descending order: for i from min(n, m) to 1.

»
9 лет назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

Apparently

You can precompute the values of ϕ in using a sieve and then compute the sum in , which should be fast enough.

I think you can use the technique from here to compute the sum in , similar to example two on the linked page, you just use the harmonic lemma for both n and m.