asim2005's blog

By asim2005, 3 years ago, In English

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

Can anybody please help me in solving this problem?

  • Vote: I like it
  • -11
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
Rev. 3   Vote: I like it +1 Vote: I do not like it

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
  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.

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

      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.

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

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

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          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.