Problem p02881 (Python) — buggy submission, verdict: Runtime Error

#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int):
    result_list = []
    for i in range(1, int(np.sqrt(N)) + 1):
        if N % i == 0:
            result_list.append(i - 1 + N // i - 1)
        else:
            pass
    print(min(result_list))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == "__main__":
    main()


Error: ImportError: libgfortran-040039e1.so.5.0.0: failed to map segment from shared object
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/.venv/lib/python3.10/site-packages/numpy/core/__init__.py", line 23, in <module>
    from . import multiarray
  File "/home/alex/Documents/bug-detection/.venv/lib/python3.10/site-packages/numpy/core/multiarray.py", line 10, in <module>
    from . import overrides
  File "/home/alex/Documents/bug-detection/.venv/lib/python3.10/site-packages/numpy/core/overrides.py", line 8, in <module>
    from numpy.core._multiarray_umath import (
ImportError: libgfortran-040039e1.so.5.0.0: failed to map segment from shared object

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02881/Python/s328405909.py", line 4, in <module>
    import numpy as np
  File "/home/alex/Documents/bug-detection/.venv/lib/python3.10/site-packages/numpy/__init__.py", line 139, in <module>
    from . import core
  File "/home/alex/Documents/bug-detection/.venv/lib/python3.10/site-packages/numpy/core/__init__.py", line 49, in <module>
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.10 from "/home/alex/Documents/bug-detection/.venv/bin/python3"
  * The NumPy version is: "1.25.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: libgfortran-040039e1.so.5.0.0: failed to map segment from shared object



Fixed submission:

#!/usr/bin/env python3
import sys
from sympy.ntheory import factorint
import numpy as np


def solve(N: int):

    fct = factorint(N)

    fct_list = []
    for key, item in zip(fct.keys(), fct.values()):
        fct_list += [key] * item

    result = 1e12

    if len(fct_list) == 2:
        x = fct_list[0]
        y = fct_list[1]
        print(x - 1 + y - 1)
    elif len(fct_list) == 1:
        x = fct_list[0]
        y = 1
        print(x - 1 + y - 1)

    else:
        for i in range(1, len(fct_list) - 1):

            x = np.prod(fct_list[: i + 1])
            y = np.prod(fct_list[i + 1 :])

            result = min(result, x - 1 + y - 1)
        print(result)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == "__main__":
    main()