Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

Автор asim2005, 4 года назад, По-английски

https://codeforces.net/problemset/problem/1250/F

Can anybody please help me in solving this problem?

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

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

loop over i: 1 to n. if n is divisible by i, then take best: (i + n / i) and minimize it. then the answer is best * 2. code:

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

    Thanks for the solution. But I could not understand the approach. What is the use of best variable in this code? And why should I minimize it? Can you please explain these to me? It would be a great help of me.

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

      best variable is used to store the minimum value of sum of any 2 non-parallel sides of the rectangle over all possible pairs of such sides.

      Doubling the value of the variable will result in the perimeter of the rectangle.

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

        OK, I understood. But why the value of the best variable is 1000000000 ? Is there any special reason behind it?

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

          That's because, no such sum can be greater that this value according to the constraints.

          You can use INT_MAX for int and LLONG_MAX for long long.

          These respective MAXs store the maximum value the can fit in the respective datatypes.