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:
import math

N = int(input())
A = []
for p in range(2,int(math.sqrt(N))+1):
    if N%p != 0:
        print(N-1)
        break
    else:
        for i in range(N//2+1):
            for j in range((N-i)//2+1):
                if N == i*j:
                    A.append(i+j-2)
    print(min(A))

Submission status: Wrong Answer

Solution code:

def solve():
    ans = 10**12
    for i in range(1, int(N**0.5)):
        if N % i == 0:
            ans = min(ans, i + (N//i) -2)
    if N == 2:
        print(1)
    elif N == 3:
        print(2)
    else:
        print(ans)
            
if __name__ == "__main__":  
    N = int(input())
    solve()

Submission status: Wrong Answer

Solution code:

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

n = int(input())


def prime_factorization(n):
    dd = defaultdict(int)
    while n % 2 == 0:
        dd[2] += 1
        n //= 2
    f = 3
    while f ** 2 <= n:
        if n % f == 0:
            dd[f] += 1
            n //= f
        else:
            f += 2
    if n != 1:
        dd[n] += 1
    return dd


pd = prime_factorization(n)

ans = 10**12
for k in pd:
    x, y = k, n // k
    ans = min(ans, x + y - 2)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N = ii()
    ret = MAX

    if N % 2 != 0 and N % 3 != 0 and N % 5 != 0 and N % 7 != 0:
        print(N + 1 - 2)
        exit()

    for n in range(1, N + 1):
        if N % n == 0:
            ret = min(ret, n + (N // n) - 2)
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

N = int(input())
ans = N - 1
for i in range(1, int(math.sqrt(N))):
    if N % i == 0:
        j = N//i
        ans = min(ans, i-1+j-1)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans=N
for i in range(1, int(N**0.5+1)):
    if N%i==0:
        a = N/i
        b = N/a
        up_ans = a + b -2
        print(up_ans)
        ans = min(ans, up_ans)
    else:
        continue
print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

N = k()
ans = 1000000

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

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product
n = int(input())

ans = n-1
for a in range(1, int(n**0.5)):
    if n%a==0:
        b = n//a
        ans = min(ans, b+a-2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
lists = []
for i in range(1, 10**6):
    if n % i ==0:
        lists.append(i + n/i)
print(int(min(lists)) - 2)

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        tmp = []
        if n % i == 0:
            tmp.append(i)
            if i != n // i:
                tmp.append(n//i)
        if(len(tmp)>0):
            divisors.append(sum(tmp))
    return divisors
def main5():
    n = int(input())
    k = make_divisors(n)
    print(min(k)-2)


if __name__ == '__main__':
    main5()

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(1, 10):
  for j in range(1, 10):
    if i*j == n:
      print(i + j - 2)
      break

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N = ii()

    ret = MAX
    for i in range(1, int((N + 1)**0.5)):
        if N % i == 0:
            j = N // i
            ret = min(ret, i + j - 2)
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def prime_fact(N):
    n = 2
    prime = []
    while n * n <= N:
        i = 0
        while N % n == 0:
            N //= n
            i += 1
        if i > 0:
            prime.append((n, i))
        n += 1
    if N != 1:
        prime.append((N, 1))
    return prime


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

    N = ii()
    prime = prime_fact(N)
    if len(prime) == 1:
        i, j = prime[0]
        print(i + j - 2)
        exit()

    ret = MAX
    for i in range(1, N + 1):
        if N % i == 0:
            j = N // i
            ret = min(ret, i + j - 2)
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import functools

N = int(input())

def factorization_list(n):
    arr = []
    tmp = n
    for i in range(2, int(-(-n**0.5//1)) + 1):
        if tmp % i == 0:
            while tmp % i == 0:
                tmp //= i
                arr.append(i)

    if tmp != 1:
        arr.append(tmp)

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

    return arr

def kuku_tuple(list):
    if len(list) == 1:
        return (1, list[0])
    elif len(list) == 2:
        return tuple(list)
    else:
        # (1,1)からの距離が一番近そうなタプルを返す
        a = [list[0]]
        b = [list[1]]
        for i in range(2, len(list)):
            if sum(a) > sum(b):
                b.append(list[i])
            else:
                a.append(list[i])
        return (functools.reduce(lambda acc, x: acc * x, a, 1),
                functools.reduce(lambda acc, x: acc * x, b, 1))


l = factorization_list(N)
t = kuku_tuple(l)
print(t[0] - 1 + t[1] - 1)

Submission status: Wrong Answer

Solution code:
n=int(input())

div = n
result = 10**12

for i in range(2,1000001):
  if n % i == 0:
    div = n // i
    result = min(result, i+div)

print(int(result-2))

Submission status: Wrong Answer

Solution code:
n=int(input())

div = n
result = 10**12

for i in range(1,int(n**0.5//1)+1):
  if n % i == 0:
    div = div // i
    result = min(result, i+div)

print(int(result-2))

Submission status: Wrong Answer

Solution code:
n=int(input())

div = 1
result = 10**12

for i in range(1,int(n**0.5//1)+1):
  if n % i == 0:
    div = div // i
    result = min(result, i+div)

print(int(result-2))

Submission status: Wrong Answer

Solution code:
n=int(input())

div = n
result = 10**12

for i in range(1,n):
  if n % i == 0:
    result = min(result, i+div)
    div = div // i

print(int(result-2))

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n = int(input())

ans = 10 ** 7
d = make_divisors(n)
#print(d)
if len(d) % 2 == 1:
  ans = d.pop(len(d)//2) * 2 - 2
#print(d, ans)
for i in range(len(d) // 2):
  t = d[i] + d[-i-1] -2
  #print(t)
  if ans > t:
    ans = t
print(ans)

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n = int(input())

ans = 10 ** 7
d = make_divisors(n)
if len(d) % 2 == 1:
  ans = d.pop(len(d)//2) * 2 - 2
#print(d)
for i in range(len(d) // 2):
  t = d[i] + d[-i-1] -2
  if ans > t:
    ans = t
print(t)

Submission status: Wrong Answer

Solution code:
n=int(input())
check=1
while check**2<n:
  if n%check==0:
    keep=n//check
  check+=1
print(keep+n//keep-2)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
min_move_count = 10**7

for i in range(1, int(math.sqrt(N)) + 1):
    if N % i == 0:
        move_count = i + (N // i) - 2
        if move_count < min_move_count:
            min_move_count = move_count

ans = min_move_count
print(ans)

Submission status: Wrong Answer

Solution code:
from math import floor, sqrt
from collections import defaultdict
def factor(n):
    dic = defaultdict(int)
    for i in range(2, floor(sqrt(n))+1):
        while n % i == 0:
            dic[i] += 1
            n //= i
    if n != 1:
        dic[n] += 1
    return dic
N = int(input())
fac = factor(N)
ans = N-1
for k in fac:
    l = N//k
    ans = min(ans, k+l-2)
print(ans)

Submission status: Wrong Answer

Solution code:

#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


N=int(input())

a=1
b=N//a
dis=abs(a-b)

for i in range(1,int(N**0.5)+1):
    if N%i==0:
        _a=i
        _b=N/i
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis

print(a-1+b-1)

Submission status: Wrong Answer

Solution code:

#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


N=100
# N=int(input())

a=1
b=N//a
dis=abs(a-b)

for i in range(1,int(N**0.5)+1):
    if N%i==0:
        _a=i
        _b=N/i
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis

print(a-1+b-1)

Submission status: Wrong Answer

Solution code:

#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


# N=100
N=int(input())

a=1
b=N//a
dis=abs(a-b)

Li=prime_factorization(N)
# print(Li)

for p in range(2**len(Li)):
    bit=[]
    for e in range(len(Li)):
        if (p>>e)&1==1:
            bit.append(1)
        else:
            bit.append(0)
    # print(bit)
        proindex=[]
        for _ in range(len(bit)):
            if bit[_] ==1:
                proindex.append(_)
        _a=1
        for j in range(len(Li)):
            if proindex.count(j)==1:
                _a*=Li[j]
        _b=N//_a
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis
        if a>N**0.5:
            break
# print(a,b)

print(a-1+b-1)

Submission status: Wrong Answer

Solution code:

#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


# N=100
N=int(input())

a=1
b=N//a
dis=abs(a-b)

Li=prime_factorization(N)
# print(Li)

for p in range(2**len(Li)):
    bit=[]
    if a>N**0.5:
        break
    for e in range(len(Li)):
        if (p>>e)&1==1:
            bit.append(1)
        else:
            bit.append(0)
    # print(bit)
        proindex=[]
        for _ in range(len(bit)):
            if bit[_] ==1:
                proindex.append(_)
        _a=1
        for j in range(len(Li)):
            if proindex.count(j)==1:
                _a*=Li[j]
        _b=N//_a
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis
# print(a,b)

print(a-1+b-1)

Submission status: Wrong Answer

Solution code:

#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


N=100
# N=int(input())

a=1
b=N//a
dis=abs(a-b)

Li=prime_factorization(N)
# print(Li)

for p in range(2**len(Li)):
    bit=[]
    if a>N**0.5:
        break
    for e in range(len(Li)):
        if (p>>e)&1==1:
            bit.append(1)
        else:
            bit.append(0)
    # print(bit)
        proindex=[]
        for _ in range(len(bit)):
            if bit[_] ==1:
                proindex.append(_)
        _a=1
        for j in range(len(Li)):
            if proindex.count(j)==1:
                _a*=Li[j]
        _b=N//_a
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis
# print(a,b)

print(a-1+b-1)

Submission status: Wrong Answer

Solution code:

#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


N=100
# N=int(input())

a=1
b=N//a
dis=abs(a-b)

Li=prime_factorization(N)
# print(Li)

for p in range(2**len(Li)):
    bit=[]
    for e in range(len(Li)):
        if (p>>e)&1==1:
            bit.append(1)
        else:
            bit.append(0)
    # print(bit)
        proindex=[]
        for _ in range(len(bit)):
            if bit[_] ==1:
                proindex.append(_)
        _a=1
        for j in range(len(Li)):
            if proindex.count(j)==1:
                _a*=Li[j]
        _b=N//_a
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis
        if a<N**0.5 or b<N**0.5:
            break
# print(a,b)

print(a-1+b-1)

Submission status: Wrong Answer

Solution code:
from heapq import heapify, heappush, heappop

def main():

    def factorization(n):
        l = [1]
        tmp = n
        i = 2
        while i*i <= n:
            if tmp%i == 0:
                while tmp%i == 0:
                    tmp //= i
                    l.append(i)
            i += 1
        if tmp != 1:
            l.append(tmp)
        if l == []:
            l.append(n)
        return l

    n = int(input())
    h = factorization(n)
    heapify(h)
    # hが2つより大きい時は2つpopして掛け算して戻すを繰り返す
    while len(h) > 2:
        a = heappop(h)
        b = heappop(h)
        heappush(h, a*b)
    a = heappop(h)
    b = heappop(h)
    # (1, 1)スタートなので2を引く
    ans = a + b - 2
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


# N=100
N=int(input())

a=1
b=N//a
dis=abs(a-b)

Li=prime_factorization(N)
# print(Li)

if len(Li)>=6:
    _a=(N**0.5)//1
    while N%_a==0:
        if N%_a==0:
            _b=N/_a
            print(_a-1+_b-1)
            exit()
        else:
            _a+=1


for p in range(2**len(Li)):
    bit=[]
    for e in range(len(Li)):
        if (p>>e)&1==1:
            bit.append(1)
        else:
            bit.append(0)
    # print(bit)
        proindex=[]
        for _ in range(len(bit)):
            if bit[_] ==1:
                proindex.append(_)
        _a=1
        for j in range(len(Li)):
            if proindex.count(j)==1:
                _a*=Li[j]
        _b=N//_a
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis
# print(a,b)


print(a-1+b-1)

Submission status: Wrong Answer

Solution code:

#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


# N=100
N=int(input())

a=1
b=N//a
dis=abs(a-b)

Li=prime_factorization(N)
# print(Li)

if len(Li)>=7:
    _a=(N**0.5)//1
    if N%_a==0:
        _b=N/_a
        print(_a-1+_b-1)
        exit()
    else:
        _a+=1


for p in range(2**len(Li)):
    bit=[]
    for e in range(len(Li)):
        if (p>>e)&1==1:
            bit.append(1)
        else:
            bit.append(0)
    # print(bit)
        proindex=[]
        for _ in range(len(bit)):
            if bit[_] ==1:
                proindex.append(_)
        _a=1
        for j in range(len(Li)):
            if proindex.count(j)==1:
                _a*=Li[j]
        _b=N//_a
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis
# print(a,b)


print(a-1+b-1)

Submission status: Wrong Answer

Solution code:

#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


# N=100
N=int(input())

a=1
b=N//a
dis=abs(a-b)

Li=prime_factorization(N)
print(Li)

for p in range(2**len(Li)):
    bit=[]
    for e in range(len(Li)):
        if (p>>e)&1==1:
            bit.append(1)
        else:
            bit.append(0)
    # print(bit)
        proindex=[]
        for _ in range(len(bit)):
            if bit[_] ==1:
                proindex.append(_)
        _a=1
        for j in range(len(Li)):
            if proindex.count(j)==1:
                _a*=Li[j]
        _b=N//_a
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis
print(a,b)
print(a-1+b-1)

Submission status: Wrong Answer

Solution code:

#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


# N=100
N=int(input())

a=N
b=1
dis=abs(a-b)

Li=prime_factorization(N)
for p in range(2**len(Li)):
    bit=[]
    for e in range(len(Li)):
        if (p>>e)&1==1:
            bit.append(1)
        else:
            bit.append(0)
    # print(bit)
        proindex=[]
        for _ in range(len(bit)):
            if bit[_] ==1:
                proindex.append(_)
        _a=1
        for j in range(len(Li)):
            if proindex.count(j)==1:
                _a*=Li[j]
        _b=N//_a
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b

print(a-1+b-1)

Submission status: Wrong Answer

Solution code:

#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


# N=100
N=int(input())

a=N
b=1
dis=abs(a-b)

Li=prime_factorization(N)
for p in range(2**len(Li)):
    bit=[]
    for e in range(len(Li)):
        if (p>>e)&1==1:
            bit.append(1)
        else:
            bit.append(0)
    # print(bit)
        proindex=[]
        for _ in range(len(bit)):
            if bit[_] ==1:
                proindex.append(_)
        _a=1
        for j in range(len(Li)):
            if proindex.count(j)==1:
                _a*=Li[j]
        _b=N//_a
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b

print(a,b)

Submission status: Wrong Answer

Solution code:

#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


N=100
# N=int(input())

a=N
b=1
dis=abs(a-b)

Li=prime_factorization(N)
for p in range(2**len(Li)):
    bit=[]
    for e in range(len(Li)):
        if (p>>e)&1==1:
            bit.append(1)
        else:
            bit.append(0)
    # print(bit)
        proindex=[]
        for _ in range(len(bit)):
            if bit[_] ==1:
                proindex.append(_)
        _a=1
        for j in range(len(Li)):
            if proindex.count(j)==1:
                _a*=Li[j]
        _b=N//_a
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b

print(a,b)

Submission status: Wrong Answer

Solution code:
#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


# N=50
N=int(input())
Li=prime_factorization(N)
if len(Li)==1:
    Li.insert(0,1)
Li_1=Li[0::2]
Li_2=Li[1::2]

a=1
b=1

for e in range(len(Li_1)):
    _=Li_1[e]
    a=a*_
for f in range(len(Li_2)):
    _=Li_2[f]
    b=b*_

print(a-1+b-1)

Submission status: Wrong Answer

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

a = math.ceil(math.sqrt(N))

yaku = {1,N}

for i in range(2,a+1):
  if N % i == 0:
    yaku.add(i)
    yaku.add(N // i)

sl = len(yaku)
lyaku =list(yaku)
if sl % 2 == 1:
  print((lyaku[sl//2]-1)*2)
else:
  print(lyaku[sl//2]+lyaku[sl//2-1] -2)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
ans=N
for i in range(1,math.floor(math.sqrt(N))):
  if N%i==0:
    ans=min(ans,i+N//i-2)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans=N
for i in range(1,10^6+1):
    if((N%i)==0):
        ans=min(ans,i+(N//i)-2)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
min_value=float('inf')
value=0
check=True
for i in range(2,10^6):
    if((N%i)==0):
        value=(N/i)+i-2
        if(min_value>value):
            min_value=value
            check=False
if(check):
    print(N-1)
else:
    print(int(min_value))

Submission status: Wrong Answer

Solution code:
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

import numpy as np
def resolve():
    N = int(input())
    res = prime_factorize(N)
    i, j = 1, 1

    i = np.prod(res[0::2])
    j = np.prod(res[1::2])

    print(int(i-1 + j-1))
    return

resolve()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import math
N = int(input())

def divisor(N):
    lst = []
    for i in range(2,math.ceil(math.sqrt(N))+1):
        if N%i == 0:
            lst.append(i)
            #if i != int(N/i):
                #lst.append(int(N/i))
    #lst.sort()
    return lst
    
ans = divisor(N)
#print(ans,len(ans))
if N == 2:
    print(1)
if len(ans) > 0:
    A = ans[-1]
    if A*A < N:
        B = int(N/A)
        print(A+B-2)
    else:
        print(2*A-2)
else:
    print(N-1)

'''
if len(ans)%2 == 0 and len(ans)>1:
    A = ans[len(ans)//2-1]
    B = ans[len(ans)//2]
    #print(A,B)
    print(A+B-2)
elif len(ans)%2 == 1 and len(ans)>1:
    A = ans[len(ans)//2]
    print(2*A-2)
else:
    print(N-1)
'''

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import math
N = int(input())

def divisor(N):
    lst = []
    for i in range(2,math.ceil(math.sqrt(N))+1):
        if N%i == 0:
            lst.append(i)
            #if i != int(N/i):
                #lst.append(int(N/i))
    #lst.sort()
    return lst
    
ans = divisor(N)
#print(ans,len(ans))
if len(ans) > 0:
    A = ans[-1]
    if A*A < N:
        B = int(N/A)
        print(A+B-2)
    else:
        print(2*A-2)
else:
    print(N-1)

'''
if len(ans)%2 == 0 and len(ans)>1:
    A = ans[len(ans)//2-1]
    B = ans[len(ans)//2]
    #print(A,B)
    print(A+B-2)
elif len(ans)%2 == 1 and len(ans)>1:
    A = ans[len(ans)//2]
    print(2*A-2)
else:
    print(N-1)
'''

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import math
N = int(input())

def divisor(N):
    lst = []
    for i in range(2,math.ceil(math.sqrt(N))+1):
        if N%i == 0:
            lst.append(i)
            if i != int(N/i):
                lst.append(int(N/i))
    lst.sort()
    return lst
    
ans = divisor(N)
#print(ans)
if len(ans)%2 == 0 and len(ans)>1:
    A = ans[len(ans)//2-1]
    B = ans[len(ans)//2]
    #print(A,B)
    print(A+B-2)
elif len(ans)%2 == 1 and len(ans)>1:
    A = ans[len(ans)//2]
    print(2*A-2)
else:
    print(N-1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import math
N = int(input())

def divisor(N):
    lst = []
    for i in range(2,math.ceil(math.sqrt(N))):
        if N%i == 0:
            lst.append(i)
            if i != int(N/i):
                lst.append(int(N/i))
    lst.sort()
    return lst
    
ans = divisor(N)

if len(ans)%2 == 0 and len(ans)>1:
    A = ans[len(ans)//2-1]
    B = ans[len(ans)//2]
    #print(A,B)
    print(A+B-2)
else:
    print(N-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
x = np.arange(1,10**6)
div = x[n%x==0]
d = len(div)
print(div[d//2]+div[d//2-1]-2)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = 10
x = np.arange(1,10**6)
div = x[n%x==0]
d = len(div)
print(div[d//2]+div[d//2-1]-2)

Submission status: Wrong Answer

Solution code:
import math
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

n = int(input())
a = 1
b = 1
tmp_ans = 0
ans = 10**10

if is_prime(n) == True:
    print(n - 1)
elif is_prime(n) == False:
    for i in range(2, int(math.sqrt(n))+1):
        j = n // i
        if n == i*j:
            tmp_ans = (i-a) + (j-b)
            if tmp_ans < ans:
                ans = tmp_ans
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()

d = []
for i in range(1,int(N**.5)+1):
    if N % i == 0:
        d.append(i)
        if i != N//i:
            d.append(N//i)

d.sort()
a = len(d)

print(d[(a-1)//2] + d[(a+1)//2] - 2)

Submission status: Wrong Answer

Solution code:
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

N=int(input())
div=make_divisors(N)

from math import sqrt

tmpmin=10*10
for i in range(len(div)):
  if tmpmin>abs(sqrt(N)-div[i]):
    tmpmin=abs(sqrt(N)-div[i])
    minidx=i

a=div[i]
b=N//a

print(a-1+b-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
lower_divisors, upper_divisors = [], []
i = 1

while i*i <= n:
    if n % i == 0:
        lower_divisors.append(i)
        if i != n // i:
            upper_divisors.append(n//i)
    i += 1

ans_i = lower_divisors[-1]
ans_j = upper_divisors[-1]

ans = (ans_i - 1) + (ans_j - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
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
k=int(input())
l=factorization(k)
tmp=float("inf")
kk=copy.deepcopy(k)
for i in range(len(l)):
    a,b=l[i][0],l[i][1]
    for j in range(b):
        kk/=a
        s=k/kk
        tt=s+kk
        if tmp>tt:
            tmp=tt
    kk=copy.deepcopy(k)
print(int(tmp-2))