Problem:
Score : 300 points

Problem Statement

Takahashi is standing on a multiplication table with infinitely many rows and columns.

The square (i,j) contains the integer i \times j. Initially, Takahashi is standing at (1,1).

In one move, he can move from (i,j) to either (i+1,j) or (i,j+1).

Given an integer N, find the minimum number of moves needed to reach a square that contains N.

Constraints

2 \leq N \leq 10^{12}

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the minimum number of moves needed to reach a square that contains the integer N.

Sample Input 1

10

Sample Output 1

5

(2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves.

Sample Input 2

50

Sample Output 2

13

(5, 10) can be reached in 13 moves.

Sample Input 3

10000000019

Sample Output 3

10000000018

Both input and output may be enormous.

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace atcoder
{
    class Program
    {
        //メイン関数
        static void Main(string[] args)
        {
            long N = long.Parse(ReadLine());
            long SavedN = N;
            long Ny = 1;

            for (int i = 2; i < SavedN; i++)
            {
                if (N <= i) break;
                for (; N % i == 0;)
                {
                    if (N <= i) break;
                    N = N / i;
                    Ny = Ny * i;
                }
            }

            WriteLine(N + Ny - 2);
        }




        #region 細々としたツール(関数)

        #region 標準入力
        //変数の入力
        static string scan() => ReadLine();
        static int scanInt() => int.Parse(ReadLine());

        //配列の入力
        static string[] MultiScan(char Split)
        {
            string[] N = ReadLine().Split(Split);
            return N;
        }
        static string[] MultiScan()
        {
            string[] N = ReadLine().Split(' ');
            return N;
        }

        static List<int> MultiScanInt(char Split)
        {
            string[] N = ReadLine().Split(Split);
            List<int> output = new List<int>();

            for (int i = 0; i < N.Length; i++)
            {
                output.Add(int.Parse(N[i]));
            }

            return output;
        }
        static List<int> MultiScanInt(char Split, int roop)
        { 
            string[] N = ReadLine().Split(Split);
            List<int> output = new List<int>();

            for (int i = 0; i < roop; i++)
            {
                output.Add(int.Parse(N[i]));
            }

            return output;
        }
        #endregion

        #region 数学関連
        public static int Gcd(int a, int b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }//最大公約数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }//最小公倍数
        public static int PlusOneSigma(int x, int loop)
        {
            int output = 0;
            for (int i = 0; i < loop; i++)
            {
                output = output + x + i;
            }
            return output;
        }//１づつ加算のシグマ
        #endregion

        #endregion
    }
}