Language: C++

//#include <bits/stdc++.h>
#include <iostream>	
using namespace std;

bool Isprime(uint64_t num)
{
	if (num < 2) return false;
	else if (num == 2)return true;

	double sqrtNum = sqrt(num);
	for (int i = 3; i < sqrtNum; i += 2) {
		if (num % i == 0)return false;
	}
	return true;
}

int main()
{
	uint64_t N;
	cin >> N;
	uint64_t dist = UINT64_MAX;
	if ((N % 2) == 0) {
		for (uint32_t A = 2; A <= (N / 2); A += 2) {
			if (((N % A) == 0)) {
				if (dist > (A + (N / A) - 2)) {
					dist = A + (N / A) - 2;
				}
			}
		}
	}
	else {
		if (Isprime(N)) {
			dist = N - 1;
			goto END;
		}
		for (uint32_t A = 1; A <= (N / 2); A += 2) {
			if (((N % A) == 0)) {
				if (dist > (A + (N / A) - 2)) {
					dist = A + (N / A) - 2;
				}
			}
		}
	}
END:
	cout << dist << endl;


	return 0;
}

Compiler output:
a.cc:5:14: error: 'uint64_t' was not declared in this scope
    5 | bool Isprime(uint64_t num)
      |              ^~~~~~~~
a.cc:3:1: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    2 | #include <iostream>
  +++ |+#include <cstdint>
    3 | using namespace std;
a.cc: In function 'int main()':
a.cc:19:9: error: 'uint64_t' was not declared in this scope
   19 |         uint64_t N;
      |         ^~~~~~~~
a.cc:19:9: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:20:16: error: 'N' was not declared in this scope
   20 |         cin >> N;
      |                ^
a.cc:21:17: error: expected ';' before 'dist'
   21 |         uint64_t dist = UINT64_MAX;
      |                 ^~~~~
      |                 ;
a.cc:23:22: error: 'uint32_t' was not declared in this scope
   23 |                 for (uint32_t A = 2; A <= (N / 2); A += 2) {
      |                      ^~~~~~~~
a.cc:23:22: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:23:38: error: 'A' was not declared in this scope
   23 |                 for (uint32_t A = 2; A <= (N / 2); A += 2) {
      |                                      ^
a.cc:25:37: error: 'dist' was not declared in this scope
   25 |                                 if (dist > (A + (N / A) - 2)) {
      |                                     ^~~~
a.cc:32:28: error: 'Isprime' cannot be used as a function
   32 |                 if (Isprime(N)) {
      |                     ~~~~~~~^~~
a.cc:33:25: error: 'dist' was not declared in this scope
   33 |                         dist = N - 1;
      |                         ^~~~
a.cc:36:22: error: 'uint32_t' was not declared in this scope
   36 |                 for (uint32_t A = 1; A <= (N / 2); A += 2) {
      |                      ^~~~~~~~
a.cc:36:22: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:36:38: error: 'A' was not declared in this scope
   36 |                 for (uint32_t A = 1; A <= (N / 2); A += 2) {
      |                                      ^
a.cc:38:37: error: 'dist' was not declared in this scope
   38 |                                 if (dist > (A + (N / A) - 2)) {
      |                                     ^~~~
a.cc:45:17: error: 'dist' was not declared in this scope
   45 |         cout << dist << endl;
      |                 ^~~~