Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- int inf_int=2e9;
- ll inf_ll=2e18;
- typedef pair<int,int> pii;
- #define pb push_back
- const double pi=3.1415926535898;
- #define dout if(debug) cout
- #define fi first
- #define se second
- #define sp setprecision
- #define debug 0
- #define up asdasd
- #define down asdasdasd
- void solve()
- {
- long double a,b,n;
- cin >> a >> b >> n;
- long double best=inf_int;
- int ans=0;
- for(int i=1;i<=n;i++)
- {
- long double x=1.0*i*a/b;
- long double up=ceil(x);
- long double down=floor(x);
- // cout << i <<" "<<x<<" "<<up<<" "<<down<<endl;
- long double dif1=abs(up/i-a/b);
- long double dif2=abs(down/i-a/b);
- if(dif1<best )
- {
- if(dif1==dif2 && up!=down)
- {
- ans+=2;
- }
- else
- {
- ans++;
- }
- }
- else if(dif2<best)
- {
- ans++;
- }
- // cout << ans<<endl;
- best=min(best,dif1,dif2);
- // cout << best<<endl;
- }
- cout << ans;
- }
- #define FILE "approximate"
- int main()
- {
- // freopen("input.txt","r",stdin);
- // freopen("output.txt","w",stdout);
- // freopen(FILE".in","r",stdin);
- // freopen(FILE".out","w",stdout);
- if(!debug)
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- }
- int t=1;
- while(t--)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement