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

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

Given an integer 1 <= N <= 100, and 1 <= MIN, MAX <= 10^5, how can I compute the number of ordered pairs (a_1, a_2, ..., a_N) such that MIN <= a_i <= MAX for any i, and gcd(a_1, a_i) = 1 for any i not equal to 1?

For example, when N = 3, MIN = 2, and MAX = 4, the valid configurations are (2,3,3), (3, 2, 2), (3, 4, 2), (3, 4, 4), (4, 3, 3), and (3, 2, 4), so the output should be "6".

I am pretty sure (not 100%) this is a DP problem, but I can't manage to come up with the solution. Also, obviously, every configuration with the first number prime is valid, but this doesn't have to be the case. Does anyone have any ideas? I have been stuck on this problem for a few days now. Maybe I'm going about it wrong, and there is a really simple solution? Print the answer modulo 10^9 + 7.

Side-note: Is it possible to get TeX to work in these blogs?

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

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

solve ur problems by urself, git gud

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Any links to the problem?

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    Here is my solution though, first bruteforce the first number, then find its prime factorization after that it is only a matter of calculating how many numbers in interval $$$[MIN;MAX]$$$ does not share a prime factor with the current candidate for $$$a_1$$$. It is easier to calculate the inverse problem ie. how many share at least one. This can be done with inclusion-exclusion principle, with that calculate the answer for numbers upto $$$MAX$$$ and upto $$$MIN-1$$$, their difference gives the answer for the interval. So we have the number of non relative primes to $$$a_1$$$ in the interval and given that a number can either be non relative prime to any other or relative prime, we also have the number of relative primes to $$$a_1$$$ in range $$$[MIN;MAX]$$$, $$$k$$$. For this fixed first number the answer is $$$k^{n-1}$$$. Complexity is bounded by the maximum number of distinct prime factors, in the given range it is six since $$$2*3*5*7*11*13<10^5$$$ but $$$2*3*5*7*11*13*17>10^5$$$, thus a definite worst-case complexity is $$$\mathcal{O}(n * 2^6)$$$.