VMSS '15 #1 - Senpai, Help Me

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 16M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

The Service Club is famous in Sōbu High School for their ability to find the optimal solution to problems, albeit not always the prettiest. One day, Isshiki Iroha, the student council president, goes to the Service Club to ask for help with student council work again. To Hikigaya Hachiman and Yukinoshita Yukino's dismay, Yuigahama Yui, being the nice girl that she is, offers to help her.

Your job is to help the Service Club solve the student council's job, as Hikigaya is too lazy to do it himself and Yukinoshita Yukino is currently busy for some reason.

The student council is to create a rectangular flower garden given A units of soil then fence it off using the least amount of fencing to save as much of the student council budget as possible. What is the minimum amount of fencing required to fence off all the soil given that the side lengths of the garden must be integers?


Oh yeah? Good on you to notice. You're right, I am nice. I've been through all kinds of things in my life, but I haven't gone out for revenge on a single person at all. If I was any other normal person, this world would've ended already. You could even call me the savior of the world.

-Hikigaya Hachiman

Input Specification

The input will consist of 1 integer A (1 \le A \le 1\,000\,000), the amount of soil the student council is given.

Output Specification

Output P, the minimum amount of fencing required to fence off the garden.

Sample Input 1


Sample Output 1



4 \times 4 has smallest perimeter P = 4 + 4 + 4 + 4 = 16

Sample Input 2


Sample Output 2



9 \times 10 has smallest perimeter P = 9 + 10 + 9 + 10 = 38


  • -4
    zys5945  commented on Sept. 22, 2015, 10:18 p.m.

    Is this a math contest?

    • 12
      Xyene  commented on Sept. 23, 2015, 11:53 a.m.