Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#include <cstdlib>
#include <iostream>
using namespace std;
int main(void) {
int n;
cin >> n;
int ans=100000;
for(int i=1;i<=n;i++){
for(int j=1;j<=n/i;j++){
if (i*j<=n){
ans=min(ans,abs(i-j)+n-i*j);
}
}
}
cout << ans << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment