Advertisement
Guest User

Untitled

a guest
Dec 19th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef unsigned long long ull;
  5. int inf_int=2e9;
  6. ll inf_ll=2e18;
  7. typedef pair<int,int> pii;
  8. #define pb push_back
  9. const double pi=3.1415926535898;
  10. #define dout if(debug) cout
  11. #define fi first
  12. #define se second
  13. #define sp setprecision
  14. #define debug 0
  15. #define up asdasd
  16. #define down asdasdasd
  17. void solve()
  18. {
  19. long double a,b,n;
  20. cin >> a >> b >> n;
  21. long double best=inf_int;
  22. int ans=0;
  23. for(int i=1;i<=n;i++)
  24. {
  25. long double x=1.0*i*a/b;
  26. long double up=ceil(x);
  27. long double down=floor(x);
  28. // cout << i <<" "<<x<<" "<<up<<" "<<down<<endl;
  29. long double dif1=abs(up/i-a/b);
  30. long double dif2=abs(down/i-a/b);
  31. if(dif1<best )
  32. {
  33. if(dif1==dif2 && up!=down)
  34. {
  35. ans+=2;
  36. }
  37. else
  38. {
  39. ans++;
  40. }
  41. }
  42. else if(dif2<best)
  43. {
  44. ans++;
  45. }
  46. // cout << ans<<endl;
  47. best=min(best,dif1,dif2);
  48. // cout << best<<endl;
  49.  
  50. }
  51. cout << ans;
  52.  
  53.  
  54. }
  55.  
  56. #define FILE "approximate"
  57. int main()
  58. {
  59.  
  60. // freopen("input.txt","r",stdin);
  61. // freopen("output.txt","w",stdout);
  62.  
  63. // freopen(FILE".in","r",stdin);
  64. // freopen(FILE".out","w",stdout);
  65. if(!debug)
  66. {
  67. ios_base::sync_with_stdio(0);
  68. cin.tie(0);
  69. cout.tie(0);
  70. }
  71.  
  72. int t=1;
  73. while(t--)
  74. solve();
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement