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

Автор yoihito, 15 лет назад, По-английски

Problem Enumerating Rational Numbers
I don't know how to solve this problem, with the help of Euler's function. Can you explain me the idea for this problem?

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

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

Не тот язык, извиняюсь.

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

Ok, got accepted.


First notice: Max denominator is 2*10^5 (from test case).
Second notice: Each denominator have exatcly phi(denominator) fractions.

After this notices you can precalculate euler functions for first 2*10^5 numbers. For determine denominator you can precalc prefix sum of euler functions and easily find denominator with binary search in this array.

After this we need to determine numerator. If determinator is num, it's exatcly (k - sum[num - 1]) coprime number with prime. It's step you can simply do with iterate from 1 to num and calc gcd.

»
15 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
We had asked a very similar question with higher constraints during IOPC last year. The problem can be found here.