AtCoder Beginner Contest 144
https://atcoder.jp/contests/abc144/tasks/abc144_c
#include<bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long min = (long long)1e18; for(long long i = 1; i <= sqrt(n); i++) { if((n % i) == 0 && ((n/i) + i - 2) < min) { min = (i + (n/i)) - 2; } } cout << min << endl; return 0; }