Advertisement
Guest User

h - Annuity payment scheme

a guest
Oct 11th, 2014
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define bps 1e-7
  4. #define eps 1e-8
  5.  
  6. using namespace std;
  7.  
  8.  
  9. double s,p;
  10. int m;
  11.  
  12. int mo(double b0){
  13.     double co = s, x = s*p + b0, a, b;
  14.     for(int i = 0; i < m; i++){
  15.         a = co*p;
  16.         b = x - a;
  17.         co -= b;
  18.     }
  19.     if(co < eps) return 1;
  20.     else return -1;
  21. }
  22.  
  23. int main(){
  24.     ios_base::sync_with_stdio(0);
  25.     #ifdef ONLINE_JUDGE
  26.     freopen("input.txt", "rb", stdin);
  27.     freopen("output.txt", "w", stdout);
  28.     #endif
  29.    
  30.     while(cin >> s >> m >> p){
  31.         p /= 100;
  32.        
  33.         double lo = 0, hi = s, mi;
  34.         while(hi-lo > bps){
  35.             mi = (lo+hi)/2;
  36.            
  37.             if(mo(mi) < 0) lo = mi;
  38.             else hi = mi;
  39.         }
  40.         cout << fixed << setprecision(6) << hi + s*p << '\n';
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement