Skip to content

Instantly share code, notes, and snippets.

@yurahuna
Created September 21, 2016 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yurahuna/bb48cff2ba12ba5a39bd85680f3f1697 to your computer and use it in GitHub Desktop.
Save yurahuna/bb48cff2ba12ba5a39bd85680f3f1697 to your computer and use it in GitHub Desktop.
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int A, B, N;
cin >> A >> B >> N;
int ans = inf;
rep2(a, 1, N + 1) {
rep2(b, 1, N + 1) {
if (B % b == 0) {
ans = min(ans, abs(A - a * (B / b)));
}
}
}
cout << ans << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment