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.



Sample input:
10


Sample output:
5

Submission status: Wrong Answer

Solution code:
#A
if False:
    N=int(input())
    E=[int(i) for i in input().split()]
    E.sort()
    s=sum(E)
    if E[-1]<s-E[-1]:
        print('Yes')
    else:
        print('No')
#B
N=int(input())
fac=[]
for i in range(1,10**6):
  if N%i==0:
    fac.append((i,N//i))
ans=10**19
for l,r in fac:
  ans=min(l-1+r-1,ans)
print(ans)
  
#C
if False:
    N=int(input())
    S=[input() for _ in range(N)]
    march=list('MARCH')
    nam=[[] for _ in range(len(march))]
    for s in S:
        if s[0] in march:
            nam[march.index(s[0])].append(s)
    ans=0
    for i in range(5):
        for j in range(i+1,5):
            for k in range(j+1,5):
                ans+=len(nam[i])*len(nam[j])*len(nam[k])
    print(ans)

#D
# N=int(input())
# ver=[[] for _ in range(N)]
# for _ in range(N-1):
#     u,v,W=map(int,input().split())
#     ver[u-1].append((v-1,W))
#     ver[v-1].append((u-1,W))
# his=[-1 for _ in range(N)]

# def dfs(i,col):
#     his[i]=col
#     for j,w in ver[i]:
#         if his[j]==-1:
#             if w%2==0:
#                 dfs(j,col)
#             else:
#                 dfs(j,(col+1)%2)

# dfs(0,0)            
# for i in range(N):
#     print(his[i])

Submission status: Wrong Answer

Solution code:
N=int(input())
fac=[]
for i in range(2,10**6):
  if N%i==0:
    fac.append((i,N//i))
ans=10**19
for l,r in fac:
  ans=min(l-1+r-1,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
N = int(input())
anslist = make_divisors(N)
anslice = anslist[len(anslist)//2-1:len(anslist)//2+1]
print(sum(anslice)-2)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
i=0
j=0
N=int(input())
Nori=N
#T, A=input().split()
#S=input()
#T=input()
#S_list=list(S)
#h_list=  list(map(int, input().split(" ")))
#M=int(input())
#drink_list = [list(map(int, input().split(" ")))for i in range(M)]
#print(T_list[1])
#T=int(T)
#A=int(A)
#不本意だが内包表記で二次元の空のリストを作成する
     
#dp=[['' for i in range(2)] for j in range(N)]
#absTH=[''for i in range(N)]
#K=int(K)
#S_list=[]
#sentence_list=[]
#total=0
#mojiretu=""
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！
#for i in range(K):
# ID_list.append(i+1)
#print(ID_list)
#for i in range(H)
#この下の行が二次元リストの読み込
#intを消して記号を読み込めるようにしたしかしこれでは文字列から読み込んでいるのと同じ
#weight_value_list =  [list(input())for i in range(N)]#一文字づつばらして入れてしまう
#s = [input() for i in range(N)]
#複数行に複数の入力値を取得し、出力する
#sentence_list =  (list(input())for i in range(N))
#for i in range(H):
#  ppixel_list=list(input())
    
#print(pixel_list)
#high_pixel_list =[['' for i in range(W)]for j in range(2*H)]
#print(high_pixel_list)
#print(pixel_list[0][1])#行　列の順番にかっこが並んでいる
#print(a_list)
first_term=0
second_term=0
#整数二次元配列を読み込む時のやり方
#a_b_c_list =  [list(map(int, input().split(" ")))for i in range(N)]
     
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！
  
     
#x, y = [0]*N, [0]*N#N個の空のリストを作成
#l = list(range(N))#範囲がNのリストを作成する
     
#for i in range(N):
#  x[i], y[i] = map(int, input().split())
#分けて入力する形式を設定することで可読性が高く仕上がっている
#素晴らしいことだ
     
     
distance = 0
#comb = list(itertools.permutations(l))
#prmutation:英語の意味としては順列である
'''p[, r]で
長さrのタプル列、重複なしのあらゆる並びを表す
今回はリストlの重複なしの並び替え順序を新たなリストに収納している
並び方を計算しリストに収納しているイメージ
l[0,1,2]
l[0,2,1]これにもリスト番号が0,1,2と割り振られている
これが全通り入っている
これ作った人はすごい
自分も早く理解したい
'''
#for i in range(0, len(comb)):#i番目のパターンの時を考える。
#  for j in range(0, N-1):#lのリスト番号を読み込み
#    distance += math.sqrt((x[comb[i][j]]-x[comb[i][j+1]])**2 + (y[comb[i][j]]-y[comb[i][j+1]])**2)
'''
各経路の距離を足していき全距離分を経路数
で割れば平均距離が出るので各経路ごとの距離は
不必要と判断されている。
'''
#print(distance/len(comb))
i=0
j=0
movepoint=10**15
#1を選んだとき0,2を選ぶってのがどう実装すべきかわからんかった
#だからここで学ぶ
#2019/1/4参考サイトに見当たらず 　仕方がないのでその場しのぎ
#for i in range(N):
# for j in range(N):
#     if N % (j+1)==0:
#         i=N/(j+1)
#         movepoint=min(movepoint,(i+j+1-2))
a = []
while N % 2 == 0:
        a.append(2)
        N //= 2
f = 3
while f * f <= N:
        if N % f == 0:
            a.append(f)
            N //= f
        else:
            f += 2
if N != 1:
        a.append(N)
x=1
y=Nori
if a==[]:
    print(Nori-1)
    sys.exit()

for i in range(len(a)):
    #print(x,y)
    movepoit=min(movepoint,(x+y-2))
    x=x*a[i]
    y=y/a[i]
    #print(x,y)
print(int(movepoit))
#print(int(movepoint))
# dp[i+1][j]=max(dp[i][j]+a_b_c_list[i],dp[i][j],dp[i][j])
#リストを一周するようにすればいいのか

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
i=0
j=0
N=int(input())
#T, A=input().split()
#S=input()
#T=input()
#S_list=list(S)
#h_list=  list(map(int, input().split(" ")))
#M=int(input())
#drink_list = [list(map(int, input().split(" ")))for i in range(M)]
#print(T_list[1])
#T=int(T)
#A=int(A)
#不本意だが内包表記で二次元の空のリストを作成する
     
#dp=[['' for i in range(2)] for j in range(N)]
#absTH=[''for i in range(N)]
#K=int(K)
#S_list=[]
#sentence_list=[]
#total=0
#mojiretu=""
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！
#for i in range(K):
# ID_list.append(i+1)
#print(ID_list)
#for i in range(H)
#この下の行が二次元リストの読み込
#intを消して記号を読み込めるようにしたしかしこれでは文字列から読み込んでいるのと同じ
#weight_value_list =  [list(input())for i in range(N)]#一文字づつばらして入れてしまう
#s = [input() for i in range(N)]
#複数行に複数の入力値を取得し、出力する
#sentence_list =  (list(input())for i in range(N))
#for i in range(H):
#  ppixel_list=list(input())
    
#print(pixel_list)
#high_pixel_list =[['' for i in range(W)]for j in range(2*H)]
#print(high_pixel_list)
#print(pixel_list[0][1])#行　列の順番にかっこが並んでいる
#print(a_list)
first_term=0
second_term=0
#整数二次元配列を読み込む時のやり方
#a_b_c_list =  [list(map(int, input().split(" ")))for i in range(N)]
     
#センテンスを暗記するのではなく、まずinput()を書いて、膨らます感じで記述する。すると#思考の流れ通りに書ける。素晴らしい！
  
     
#x, y = [0]*N, [0]*N#N個の空のリストを作成
#l = list(range(N))#範囲がNのリストを作成する
     
#for i in range(N):
#  x[i], y[i] = map(int, input().split())
#分けて入力する形式を設定することで可読性が高く仕上がっている
#素晴らしいことだ
     
     
distance = 0
#comb = list(itertools.permutations(l))
#prmutation:英語の意味としては順列である
'''p[, r]で
長さrのタプル列、重複なしのあらゆる並びを表す
今回はリストlの重複なしの並び替え順序を新たなリストに収納している
並び方を計算しリストに収納しているイメージ
l[0,1,2]
l[0,2,1]これにもリスト番号が0,1,2と割り振られている
これが全通り入っている
これ作った人はすごい
自分も早く理解したい
'''
#for i in range(0, len(comb)):#i番目のパターンの時を考える。
#  for j in range(0, N-1):#lのリスト番号を読み込み
#    distance += math.sqrt((x[comb[i][j]]-x[comb[i][j+1]])**2 + (y[comb[i][j]]-y[comb[i][j+1]])**2)
'''
各経路の距離を足していき全距離分を経路数
で割れば平均距離が出るので各経路ごとの距離は
不必要と判断されている。
'''
#print(distance/len(comb))
i=0
j=0
movepoint=10**15
#1を選んだとき0,2を選ぶってのがどう実装すべきかわからんかった
#だからここで学ぶ
#2019/1/4参考サイトに見当たらず 　仕方がないのでその場しのぎ
#for i in range(N):
for j in range(N):
    print(j)
    if N % (j+1)==0:
        i=N/(j+1)
        movepoint=min(movepoint,(i+j+1-2))

print(int(movepoint))
# dp[i+1][j]=max(dp[i][j]+a_b_c_list[i],dp[i][j],dp[i][j])
#リストを一周するようにすればいいのか

Submission status: Wrong Answer

Solution code:
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


n = load()

ps = []
for i in range(1, int(math.sqrt(n))+1):
    if n % i ==0:
        ps.append((i, int(n/i)))
print(ps)
if not ps:
    print(n-1)
    exit()
mn = min(ps, key=lambda p: p[0] + p[1])
print(mn[0]-1 + mn[1]-1)

Submission status: Wrong Answer

Solution code:
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


n = load()

ps = []
for i in range(1, int(math.sqrt(n))):
    if n % i ==0:
        ps.append((i, int(n/i)))
if not ps:
    print(n-1)
    exit()
mn = min(ps, key=lambda p: p[0] + p[1])
print(mn[0]-1 + mn[1]-1)

Submission status: Wrong Answer

Solution code:
import sys
import math
input = sys.stdin.readline

def main():
    N = int(input())
    if N == 1:
        print(0)
        quit()

    ans = float('INF')
    m = math.ceil(N ** 0.5)
    for a in range(1, m):
        if N % a == 0:
            b = N // a
            ans = min(ans, (a + b - 2))

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
input = sys.stdin.readline

def main():
    N = int(input())

    ans = float('INF')
    m = math.ceil(N ** 0.5)
    for a in range(1, m):
        if N % a == 0:
            b = N // a
            ans = min(ans, (a + b - 2))

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from functools import reduce
from operator import mul
input = sys.stdin.readline

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
    N = int(input())
    l = prime_factorize(N)

    if len(l) == 1:
        l = l + [1]
    elif len(l) == 2:
        pass
    elif len(l) > 2:
        part = math.ceil(len(l) / 2)
        head = math.ceil(part / 2)
        tail = math.floor(part / 2)

        left = l[:head] + l[-tail:]
        right = l[head:-tail]
        l = [reduce(mul, left), reduce(mul, right)]

    print(sum(l) - 2)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

i = 1
j = 1 
l = []
while i <= (N/i):

  if N%i == 0:
    j = int(N/i)
    l.append([i,j])
  
  i+=i

res = l.pop()

print(res[0]+ res[1] -2)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=n
for i in range(1,int(n**.5)+1):
    if n%i==0:
        m=min(m, n//i+i)
print(m-2)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 10**12+10
for i in range(1, int(N**0.5)):
    if N%i==0:
        ans=min(ans, i+N//i-2)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import sys

n = int(input())

l = []
if n == 2:
    print(1)
else:
    for i in range(2, int(math.sqrt(n) + 1)):
        if n % i == 0:
            for i in range(1, int(math.sqrt(n)) + 1):
                if n % i == 0:
                    j = n // i
                    l.append(i + j)
            print(min(l) - 2)
            sys.exit()
print(n -1)

Submission status: Wrong Answer

Solution code:
import math
import sys

n = int(input())

l = []
if n == 2:
    print(1)
else:
    for i in range(2, int(math.sqrt(n) + 1)):
        if n % i == 0:
            for i in range(1, int(math.sqrt(n))):
                if n % i == 0:
                    j = n // i
                    l.append(i + j)
            print(min(l) - 2)
            sys.exit()
print(n -1)

Submission status: Wrong Answer

Solution code:
import math
import sys
n = int(input())

l = []
if n == 2:
    print(1)
else:
    for i in range(2, int(math.sqrt(n) + 1)):
        if n % i == 0:
            for i in range(1, n // 2 + 1):
                for j in range(1, n // 2 + 1):
                    if i * j == n:
                        l.append(i + j)
            print(min(l) - 2)
            sys.exit()
            


print(n - 1)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
min_ans = N

for a in range(1, math.ceil(N ** (1 / 2))):
    if N % a != 0:
        continue
    b = N // a
    min_ans = min(min_ans, a + b - 2)

print(int(min_ans))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
min_ans = 10 ** 12

for a in range(1, math.ceil(N ** (1 / 2))):
    b = N / a
    if b.is_integer():
        min_ans = min(min_ans, a + b - 2)

print(int(min_ans))

Submission status: Wrong Answer

Solution code:
import functools
import operator


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    if len(a) == 1:
        a.append(1)
    return a


N = int(input())
min_ans = 10 ** 12
prime_list = prime_factorize(N)
left_val = prime_list[0]
prod = functools.partial(functools.reduce, operator.mul)
right_val = prod(prime_list) / left_val
for i in range(1, len(prime_list)):
    min_ans = min(min_ans, left_val + right_val - 2)
    left_val *= prime_list[i]
    right_val /= prime_list[i]

print(int(min_ans))

Submission status: Wrong Answer

Solution code:
import functools
import operator


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    if len(a) == 1:
        a.append(1)
    return a


N = int(input())
min_ans = 10 ** 12
prime_list = prime_factorize(N)
left_val = prime_list[0]
prod = functools.partial(functools.reduce, operator.mul)
right_val = prod(prime_list) / left_val
for i in range(1, len(prime_list)):
    min_ans = min(min_ans, left_val + right_val - 2)
    left_val *= prime_list[i]
    right_val /= prime_list[i]

print(min_ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
i=0
s=[]
p=0
for i in range(n):
    i+=1
    if i<10 and p==0:
        print(n-1)
        quit()
        break
    if n%i==0:
        p=1
        s.append(n//i+i-2)
print(min(s))

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n = int(input())

a = make_divisors(n)
l = len(a)

if l % 2 == 0:
	print(a[l//2-1] + a[l//2] - 2)
else:
	print(a[l//2]**2 - 2)

Submission status: Wrong Answer

Solution code:
N = int(input())
N_2 = int(N ** 0.5)
ans = float('Inf')
for i in range(1, N_2):
    if N % i == 0:
        s = i + N / i - 2
        ans = min(ans, int(s))
print(ans)

Submission status: Wrong Answer

Solution code:


import math


def submit():
    n = int(input())

    min_manhattan = float('inf')
    for x in range(1, math.ceil(math.sqrt(n))):
        q, mod = divmod(n, x)
        if mod:
            continue

        if x + q < min_manhattan:
            min_manhattan = x + q

    print(min_manhattan - 2)


if __name__ == "__main__":
    submit()

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
p=math.sqrt(n)
def x(g):
  a=g
  c=0
  while a>=0:
    a-=1
    c+=1
  return c-1

m=x(p)
for i in range(m):
  if n%(m-i)==0:
    print(m-i+(n//(m-i)))
    break

Submission status: Wrong Answer

Solution code:
import math
def is_prime(n):
    for i in reversed(range(2,math.ceil(n**0.5))):
        if n%i == 0:
            print(n//i+i-2)
            exit()
    print(n-1)

N = int(input())
is_prime(N)

Submission status: Wrong Answer

Solution code:
N = int(input())

x = 1
y = 1
cnt = 0
flag = True
while flag:
    #cnt += 1
    for i, j in ([0, 1], [1, 0]):
        a = x + i
        b = y + j
        if a * b == N:
            print(cnt + 1)
            flag = False
            break
    cnt += 1
    x = a
    y = b

Submission status: Wrong Answer

Solution code:
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

def solve():
    N = int(input())
    ans = 10 ** 12
    # A = []
    # for i in range(1, int(N ** 0.5)+1):
    #     if N % i == 0:
    #         a = N // i
    #         A.append(a+i)
    #         ans = min(ans, a+i)

    a = 1    
    B = []
    l = factorize(N)
    for i in l:
        a *= i
        b = N / a
        B.append(a+b)
        ans = min(ans, int(a+b))
        
    return ans-2

print(solve())

Submission status: Wrong Answer

Solution code:
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

def solve():
    N = int(input())
    l = factorize(N)
    ans = 10 ** 12
    a = 1
    for i in l:
        a *= i
        b = N / a
        ans = int(min(ans, a+b))
    return ans-2

print(solve())

Submission status: Wrong Answer

Solution code:
def is_prime(n):
    if n < 2:
        return False
    elif n == 2:
        return True
    if n % 2 == 0:
        return False

    for i in range(3, int(n ** 0.5) + 1):
        if n % i == 0:
            return False

    return True

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

def solve():
    N = int(input())
    l = factorize(N)
    
    if is_prime(N): 
        return N-1
    
    ans = 10 ** 9
    a = 1
    for i in l:
        a *= i
        b = N / a
        ans = int(min(ans, a+b))
    return ans-2

print(solve())

Submission status: Wrong Answer

Solution code:
import collections
import numpy as np
N = int(input())

def prime_factorize(n):
    ans = [1]
    i = 2
    while i * i <= n:
        if n % i == 0:
            n //= i
            ans.append(i)
        else:
            i += 1
    if n != 1:
        ans.append(n)
    
    return sorted(ans)


primes = prime_factorize(N)
prod = np.prod(np.array(primes)) 
primes = collections.deque(primes)
ans = prod - 1

for k in range(len(primes) - 1):
    for i in range(1, len(primes)):
        i_next = np.prod(np.array(primes)[:i])
        ans = min(ans, i_next + prod // i_next - 2)
    primes.append(primes[0])
    primes.popleft()
    
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
  n=int(input())
  t=0
  for x in range(2,int(n**0.5)+1):
    if n%x==0:
      return x+n//x-2
  return n-1
if __name__ == '__main__':
  print(main())

Submission status: Wrong Answer

Solution code:
def main():
  n=int(input())
  t=0
  for x in range(1,int(n**0.5)+1):
    if n%x==0:
      return x+n//x-2
  return n-1
if __name__ == '__main__':
  print(main())

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())

def prime_factorize(n):
    ans = [1]
    i = 2
    while i * i <= n:
        if n % i == 0:
            n //= i
            ans.append(i)
        else:
            i += 1
    if n != 1:
        ans.append(n)
    
    return np.array(sorted(ans))


primes = prime_factorize(N)
ans = False

for i in range(1, len(primes)):
    calc = np.prod(primes[:i]) - 1 + np.prod(primes[i:]) - 1
    if ans is not False:
        ans = min(ans, calc)
    else:
        ans = calc
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())

def prime_factorize(n):
    ans = []
    i = 2
    while i * i <= n:
        if n % i == 0:
            n //= i
            ans.append(i)
        else:
            i += 1
    if n != 1:
        ans.append(n)
    
    return np.array(sorted(ans))

primes = prime_factorize(N)
ans = np.prod(primes) - 1

for i in range(1, len(primes)):
    calc = np.prod(primes[:i]) - 1 + np.prod(primes[i:]) - 1
    if calc < ans:
        ans = calc
    else:
        print(ans)
        exit()
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
N2 = N ** (1 / 2)
ans = float("inf")
for i in range(1, int(N2)):
    if N % i == 0:
        a = i + (N // i) - 2
        if ans > a:
            ans = a
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
ans = 10**12
if N%2 == 0:
  for i in range(1,10**6+1):
    j = math.ceil(N/(i+1))
    if (1+i)*j == N:
      ans = min(i+j-1,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
a=int(input())
k=[]
while a%2==0:
  a//=2
  k+=[2]
t=3
while t**2<=a:
  if a%t==0:
    a//=t
    k+=[t]
  else:t+=2
k+=[a]
z=[1,1]
for i in range(len(k)):
  z[i%2]*=k[i]
print(sum(z)-2)

Submission status: Wrong Answer

Solution code:
import math

def main():
    N = int(input())

    minimum = 10**12
    for i in range(1,math.floor(N**0.5)):
        if(N % i == 0):
            x = i
            y = N // i

            if(minimum > x+y):
                minimum = x + y

    print(minimum - 2)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

def main():
    N = int(input())

    minimum = 10**12
    for i in range(1,math.floor(N**0.5)):
        if(N % i == 0):
            x = i
            y = N / i

            if(minimum > x+y):
                minimum = x + y

    print(int(minimum) - 2)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
n = int(input())

min = n + 1
for i in range(1,int(math.sqrt(n))):
    if n%i==0:
        min = i + (n // i) if min > i + (n // i) else min

print(min - 2)

Submission status: Wrong Answer

Solution code:
N = int(input())

#約数列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

yaku = make_divisors(N)
ans = yaku[-1] + yaku[-2] -2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

fact = prime_factorize(n)
if(len(fact) == 1): print(fact[0]-1)
else:
    while len(fact) > 2:
        tmp_arr = []
        for i in range(len(fact) // 2):
            tmp = fact.pop(0) * fact.pop(-1)
            tmp_arr.append(tmp)
            if len(fact) == 1: tmp_arr.append(fact[0])
        fact = tmp_arr
    print(fact[0]+fact[1] - 2)

Submission status: Wrong Answer

Solution code:
N=int(input())
for i in range(int(N**0.5)+1,1,-1):
  if N%i==0:
    print(N/i+i-2)

Submission status: Wrong Answer

Solution code:
N = int(input())

# 証明できないけど、真ん中の方の数字の方が数を足すと小さい値になると思う。
for n in reversed(range(1, int(N/2) + 1)):
  if N % n == 0:
    a = int(n + N/n)
    break


print(a - 2)

Submission status: Wrong Answer

Solution code:

n = int(input())
number = int(n ** 0.5)
ans = 1000000000000

for i in range(1,number):
    if n % i == 0:
        tmp = i + int(n / i) -2
        if tmp < ans:
            ans = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())

U = np.arange(1, n ** 0.5, dtype = np.int64)

div = U[n % U == 0]

ans = min((n / div) + div) - 2

print(int(ans))

"""old


from itertools import combinations
import numpy as np

n = int(input())

a = 2
cnt = 0
ans = []


def walk_counter(ll, n):
    left = np.prod(ll)
    right = n // left
    return left + right - 2


tmp_n = n

while tmp_n >= a:
    while tmp_n % a == 0:
        tmp_n = tmp_n // a
        # cnt += 1
        ans.append(a)
    # if cnt > 0:
    #     ans.append([a, cnt])
    #     cnt = 0
    a = a + 1

if tmp_n == a:
    ans.append(a)

fin = 0

for i in range(len(ans)):
    for v in combinations(ans, i):
        tmp = walk_counter(v, n)
        if i == 0:
            fin = tmp
        elif fin > tmp:
            fin = tmp

# 組み合わせでなく、√nまでの試し割法のほうが早い

print(fin)
"""

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import numpy as np

n = int(input())

a = 2
cnt = 0
ans = []


def walk_counter(ll, n):
    left = np.prod(ll)
    right = n // left
    return left + right - 2


tmp_n = n

while tmp_n >= a:
    while tmp_n % a == 0:
        tmp_n = tmp_n // a
        # cnt += 1
        ans.append(a)
    # if cnt > 0:
    #     ans.append([a, cnt])
    #     cnt = 0
    a = a + 1

if tmp_n == a:
    ans.append(a)

fin = 0

for i in range(len(ans)):
    for v in combinations(ans, i):
        tmp = walk_counter(v, n)
        if i == 0:
            fin = tmp
        elif fin > tmp:
            fin = tmp

print(fin)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 10**13
for i in range(1,int(N**0.5)+1) :
    if N%i == 0 :
        print(i, N//i)
        ans = min(ans, i + N//i - 2)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            tmp = []
            tmp.append(i)
            tmp.append(n//i)
            divisors.append(tmp)
    return divisors

L = divisors(N)
ans = float('inf')
print(L)
for l in L:
    tmp = sum(l) - 2
    ans = min(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            tmp = []
            tmp.append(i)
            if i != n // i:
                tmp.append(n//i)
            if len(tmp)>1:
                divisors.append(tmp)
    return divisors

L = divisors(N)
ans = float('inf')
for l in L:
    tmp = sum(l) - 2
    ans = min(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            tmp = []
            tmp.append(i)
            if i != n // i:
                tmp.append(n//i)
            divisors.append(tmp)

    #divisors.sort()
    return divisors

L = divisors(N)
ans = float('inf')
for l in L:
    tmp = sum(l) - 2
    ans = min(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import os
import math

def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.readline().rstrip())

    max = int(math.sqrt(N) // 1)
    ret = float('inf')
    for i in range(1, max):
        q, mod = divmod(N, i)
        if mod == 0:
            j = N // i
            ret = min(ret, ((j-1)+(i-1)))

    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.readline().rstrip())

    ret = float('inf')
    for i in range(1, 1000000):
        q, mod = divmod(N, i)
        if mod == 0:
            j = N // i
            ret = min(ret, ((j-1)+(i-1)))

    print(ret)


if __name__ == '__main__':
    main()