Изменения рейтингов за последние раунды временно удалены. Скоро они будут возвращены. ×

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

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

Hello Codeforces!

I have been asked by people in my Discord server and on my YouTube channel to explain my approach for F, and in my opinion, it ended up being an approach worth of writing a separate blog for it, since it's a bit different from the editorial approach and also more intuitive(at least in my opinion).

My solution is slightly different from editorial's, and it relies on using the problem constraints and also on the fact that we only have to respect one of the errors to get a correct verdict, as I'm going to show below.

We will also start from the well known divisor formula:

$$$n$$$ $$$=$$$ $$$a_1^{b1}$$$ $$$*$$$ $$$a_2^{b2}$$$ $$$*$$$ ...$$$*$$$ $$$a_k^{bk}$$$, the number of divisors is $$$(b1+1)$$$ $$$*$$$ $$$(b2+1)$$$ $$$*$$$ ... $$$*$$$ $$$(bk+1)$$$.

Basically, the solution is made of two parts. The first part consists in grouping the prime numbers up to $$$677$$$ in groups such that their product does not exceed $$$10^{18}$$$(the biggest number I could get to by grouping the primes in increasing order, this bound can definitely be made bigger by grouping the primes in a better way, however this is not necessary for this task). Why $$$677$$$? Because grouping requires $$$17$$$ queries, which leaves us with $$$5$$$ more queries to use.

Now, using these $$$17$$$ queries, we can find which queries up to $$$677$$$ show up in the number's prime factorization(For now, we don't care about the power at which they show up, we just want to check if they show up or not). In order to do this, for every prime in the current group, we're going to check if the obtained $$$GCD$$$ divides that prime and add it in an array of prime divisors. Since the product of the first $$$10$$$ primes already exceeds $$$10^{9}$$$, this means we're going to have at most $$$9$$$ primes in the number's factorization.

Since we can ask $$$5$$$ extra queries, we can find the exact power at which each of the smaller primes in factorization shows up at. In order to do this effectively, we will group primes in pairs of two and create some big numbers like this, where $$$a$$$ and $$$b$$$ are prime numbers:

Let's note $$$floor(\log_a 10^9)$$$ with $$$pa$$$ and $$$floor(\log_b 10^9)$$$ with $$$pb$$$

Then, the number will look like this $$$a^{pa}$$$ * $$$b^{pb}$$$.

This number won't exceed $$$10^{18}$$$ and by using GCD, we can find for each power at which it appears in the given number.

After finding the powers at which the smaller prime numbers appear in the given number, all we have to do is print the answer. I'm going to show that it's enough to print $$$max(ans+7, ans*2)$$$.

Why does $$$max(ans+7, ans*2)$$$ work?

My method can miss at most three factors, let's note them $$$p$$$, $$$q$$$ and $$$r$$$(they have to be distinct in order to get us the worst case, according to the divisor formula). Also, they have to be bigger than $$$677$$$ in order to get them missed in my solution. There can't be $$$4$$$ big missed factors because $$$677^{4}$$$ is way bigger than $$$10^{9}$$$.

If I don't miss any prime factor, printing $$$ans*2$$$ is fine, since the relative error will be $$$2$$$ $$$(\frac{ans}{real ans} = 2)$$$

If I miss one prime factor, then printing $$$ans*2$$$ is actually the correct answer.

If I miss two prime factors, printing $$$ans*2$$$ will give a relative error of $$$0.5$$$, which is also fine.

If I miss three prime factors, printing $$$ans+7$$$ will be fine, since the maximal number of divisors for some number of type $$$X * p * q * r$$$ is $$$16$$$ (We can have at most one extra prime factor without passing $$$10^{9}$$$, and in the worst case, ans will always be $$$1$$$, and the relative error will be $$$0.5$$$, which is fine enough.

Also, printing at least $$$8$$$ every time ensures that I will never miss any number with divisor count in range $$$[1, 16]$$$.

Therefore, I managed to get AC using this method. Sadly, I got WA in system tests because I printed $$$ans*2$$$ instead of $$$max(ans+7, ans*2)$$$ in the last case I talked about in blog.

Submission link: 80521041

I hope you enjoyed reading, even though it's quite a long editorial.

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

»
5 лет назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

This is the exact same solution as in editorial.

The only difference is that you work backwards from 22 queries, not from $$$10^{9}$$$ which is not great. You are saying "well, I did what I could with the 22 queries I have, let's check that it works".

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

    Well, you're right that it sounds similar, I just found this approach easier to explain to people who asked me and didn't understand the editorial approach.

    I didn't claim it's the best approach, I just said that it works for this task.

    Still, thanks for feedback.