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

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

I was giving this round https://mirror.codeforces.com/contest/1542 and wasn't able to solve problem B. Though after just a small hint I was able to solve it but I can't get over the fact that I wasn't able to approach this question . are the some good resources for constructive algorithm questions or its just natural for some people ? if there are some good resources please do share them. It's not just the mentioned contest I want to improve ability to solve constructive algorithm questions in general.

thanks in advance

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

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

Problem B could have been solved if you just knew, $$$gcd(a,b)=gcd(a,b-a)$$$.

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

    how ? can you be a bit more elaborate

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

      Initially the set has only $$${1}$$$.

      The two operations are :

      1- $$$x*=a$$$

      2- $$$x+=b$$$

      So, for any number $$$n$$$, if $$$gcd(n,b)=1$$$ then it means we can obtain it by using 2nd operation repeatedly, since $$$gcd(b,k*b+1)=gcd(b,(k-1)*b+1)=\cdots=gcd(b,1)=1$$$

      Now , if we apply operation-1 at any time, the number becomes a multiple of $$$a$$$.

      Let's analyse the terms obtained in the number after doing operation-1, if we do it after 2nd operation, all terms are the multiples of $$$b$$$ except the terms like $$$a,a^2,a^3\cdots$$$, so if $$$n$$$%b = $$$a^p$$$ %b for some number p, then n is present in the set.