Another Contest 5 Problem 1 - Goat Fence

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 1.0s
Memory limit: 256M

Problem type

Tudor is building a pen for his N goats. N goats need a rectangular pen with area exactly N square meters to roam.

Tudor needs to buy some fencing to demarcate the pen. The fencing comes in one meter units, so the rectangular pen must have side lengths that are an integer number of meters.

Tudor will randomly select, among all such possible rectangular pens with area N square meters, one pen to build. Compute the minimum amount of fencing, in meters, that Tudor needs to buy to guarantee that he can build the randomly selected pen.


1 \le N \le 100

Input Specification

The first and only line of input contains a single positive integer, N.

Output Specification

Output the minimum amount of meters of fencing Tudor must buy.

Sample Input


Sample Output



  • 0
    PhoenixCoolIce  commented on April 16, 2024, 3:10 p.m.

    But for this question, you don't need a \n? Did they change it, because when I submitted, you didn't need a \n an if you put a \n it gives a presentation error instead?

    • 0
      PhoenixCoolIce  commented on April 16, 2024, 3:10 p.m.

      It says in the contest page that you need a \n

      • 0
        BalintR  commented on April 16, 2024, 8:30 p.m.

        PrintStream.println in Java already adds a newline character at the end of the line. So System.out.println("123"); follows the required format and so does System.out.print("123\n");.

        • 0
          PhoenixCoolIce  commented on April 16, 2024, 10:23 p.m.

          Once again, I'm dumb

  • 6
    ypaula521  commented on Aug. 24, 2020, 1:59 p.m.

    TIL that I can't read.

    • -1
      Xiang_li  commented on July 27, 2021, 8:07 p.m.

      same. I thought you were supposed to output the minimum fencing. Oops.

  • -12
    yeebruh21  commented on Aug. 15, 2020, 7:17 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.

    • 5
      Hubie  commented on Aug. 15, 2020, 11:33 p.m. edited

      It doesn't matter if N is a perfect square or not, all areas can be represented with at least 1 rectangular pen.

  • 2
    BULLET999  commented on Jan. 8, 2020, 2:37 a.m.

    big bruh moment

  • 4
    redfirearne  commented on July 25, 2019, 11:37 p.m. edit 2

    Why am I getting Presentation Error, check your whitespace?

    Edit: I know it means that I have either too many whitespaces or I'm missing some. But I don't have any whitespaces in my output, and I don't think we need to in this question?

    • 9
      wleung_bvg  commented on July 25, 2019, 11:44 p.m.

      If you look at the contest page, you will see that it states the following:

      The contest will follow the standard convention of having all lines terminate in a \n character.