Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

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

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

I was giving this round https://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
  • Проголосовать: не нравится

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

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

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

    how ? can you be a bit more elaborate

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 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.

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

        I don't understand why to bother about gcd, all we care about is

        n — a ^ x (x >= 0) to be divisible by b right?

        I can't think in terms of gcd so it feels pretty complicated to me

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

          n — a ^ x (x >= 0) to be divisible by b

          This condition is not sufficient, and I don't think you can solve it without thinking about gcd.

          Edit: It's correct, I misread the overly large minus sign.

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

            Could you provide some proof for why you think this condition is not sufficient? My solution based on just that one equation got accepted.

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

        So, for any number n, if gcd(n,b)=1 then it means we can obtain it by using 2nd operation repeatedly, Sorry, but I don't understand this statement. If b = 3, and n = 5, then gcd(3, 5) = 1. But how can we obtain 5 by just doing 1 + b + b... ?