E. Insane Problem | Codeforces Round 993 (Div. 4)

Поделиться
HTML-код
  • Опубликовано: 23 дек 2024

Комментарии • 6

  • @rishabhinc2936
    @rishabhinc2936 7 дней назад

    why (l2+kn-1)/kn.Could u please explain

    • @codeNLearnNCode
      @codeNLearnNCode  7 дней назад

      in order to take the ceil value. Assume we are dividing 15 by 7 this will give some value 2.1.. but i'm and interested in value that should be greater than 2 so if i add n-1 that is 6 in this case it will be 21/7 that will give me 3.

    • @rishabhinc2936
      @rishabhinc2936 7 дней назад

      @@codeNLearnNCode ok so its basically an alt to ceil method

    • @codeNLearnNCode
      @codeNLearnNCode  7 дней назад +1

      Yes

  • @_Dream_Dive_
    @_Dream_Dive_ 7 дней назад

    sir can u provide the solution link i

    • @codeNLearnNCode
      @codeNLearnNCode  2 дня назад

      #include
      #include
      using namespace std;
      long long power(long long base, long long exp, long long limit)
      {
      long long result = 1;
      while (exp > 0)
      {
      if (result > limit / base)
      return limit + 1;
      result *= base;
      exp--;
      }
      return result;
      }
      void solve()
      {
      long long k, l1, r1, l2, r2;
      cin >> k >> l1 >> r1 >> l2 >> r2;
      long long count = 0;
      for (long long n = 0;; ++n)
      {
      long long kn = power(k, n, r2);
      if (kn > r2)
      break;
      long long min_x = max(l1, (l2 + kn - 1) / kn);
      long long max_x = min(r1, r2 / kn);
      if (min_x