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;
}

 

posted @ 2019-10-28 00:33  晴屿  阅读(167)  评论(0编辑  收藏  举报