Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <iostream>
- using namespace std;
- const long double inf = 9e18;
- const long double eps = 1e-16;
- long double a, b;
- long double f (int x, int y) {
- return fabs (x * 1.0 / y - a / b);
- }
- bool eq (long double a, long double b) {
- return fabs (a - b) < eps;
- }
- int main () {
- freopen ("approximate.in", "r", stdin);
- freopen ("approximate.out", "w", stdout);
- int n;
- cin >> a >> b >> n;
- int l = 0;
- int ans = 0;
- long double mn = inf;
- for (int i = 1; i <= n; i++) {
- while (l < i && f (l + 1, i) < f (l, i)) {
- l++;
- }
- if (f (l, i) < mn) {
- ans += 1 + eq (f (l + 1, i), f (l, i));
- mn = f (l, i);
- }
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment