Please read the new rule regarding the restriction on the use of AI tools. ×

dakshgarg's blog

By dakshgarg, history, 4 years ago, In English

We invite you to participate in CodeChef’s Inferno Numero IIT BHU, running this Sunday, 3rd January, from 20:00 pm to 22:00 pm IST. The contest features 6 problems and is 2 hours long.

The Contest is organized by team SPYB!TS IIT BHU.

This is a coding contest based on algorithms, number theory, data structures and problem solving.

Here is the problemsetting panel:
Setters: adikrsingh , Gol.D.Roger , dakshgarg
Tester: emperor_gentoo , masteranimax , gaddopur_coder

Good luck and have fun!

  • Vote: I like it
  • +55
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it +8 Vote: I do not like it

What would be the Prizes for the Winners?

Also, is the Round Rated ?

  • »
    »
    4 years ago, # ^ |
    Rev. 2   Vote: I like it +16 Vote: I do not like it

    There will be 250 Laddus each to Top 3 Global Winners.
    Contest is open for all (not rated).

»
4 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

In this problem Illuminated Boxes I simply printed (n*m) /gcd(n, m) and it got accepted. I reached at this point mostly by intuition but couldn't prove it. Can anyone who solved this problem share the proof uwi, nuip, EnEm, gupta_samarth, TheAnshul ?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    Assume WLOG $$$n \geq m$$$.

    If we plot the points $$$[0,n-1]$$$ in the x-axis, we can see that the laser will strike the points between them and for every two consecutive points, it will cross exactly $$$m$$$ boxes.

    Every striking point box will be different ( Otherwise the laser retracing it's path, which is not possible ).

    So we only need to find the number of distinct points strikes in the range $$$[0,n-1]$$$, times $$$m$$$.

    That is exactly equal to $$$\dfrac{n\times m}{gcd(n,m)}$$$.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +28 Vote: I do not like it

    Being a LGM doesn't mean you will go on tagging every person rated lower than you :P

»
4 years ago, # |
  Vote: I like it +4 Vote: I do not like it

How to solve problem: WIN IT? any editorial Link?

  • »
    »
    4 years ago, # ^ |
    Rev. 4   Vote: I like it +13 Vote: I do not like it

    I didn't solve it in contest but I do have a solution,

    Since the number of distinct primes is atmost 10, you can create 10 range-query trees. And each number will be stored as a product of prime factors $$$p_1^a,p_2^b\dots$$$

    You can update all the primes factors in $$$O(10\log A_i)$$$, and for each query, use these lemma to answer them

    For prime number $$$a,b$$$

    $$$\phi(a^k) = a^k - a^{k-1}$$$

    $$$\phi(a\times b) = \phi(a)\times \phi(b)$$$

    You'd likely need coordinate compression in this, and pre calculated Sieve for factorization in $$$O(\log n)$$$

    This was my idea, though I would like to know if there is any cleaner and efficient implementation to this.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it
  • »
    »
    4 years ago, # ^ |
    Rev. 2   Vote: I like it +9 Vote: I do not like it

    The idea was to somehow calculate the power of all the primes in $$$l$$$ to $$$r$$$ for $$$2^{nd}$$$ query and also it should be convenient to update when we change the value for the $$$1^{st}$$$ query. Because the number of primes at any moment is less than 10 so we can maintain separate Fenwick tree for each prime. Now that we have the power of each prime in multiplication from $$$l$$$ to $$$r$$$ we can use the formula

    $$$ \phi (n) = p_{1}^{a_{1}} . (1 - \frac{1}{p_{1}}) . p_{2}^{a_{2}} . (1 - \frac{1}{p_{2}}) \cdots p_{k}^{a_{k}} . (1 - \frac{1}{p_{k}}) $$$

    where $$$n = p_{1}^{a_{1}} . p_{2}^{a_{2}} \cdots p_{k}^{a_{k}}$$$.

    Also, don't forget to update the list of those 10 primes for Fenwick Tree as they get changed so once the sum of powers for any prime overall $$$n$$$ become 0 remove that prime. I made two wrong submissions because of this mistake.

    Here is my AC code.