Advertisement
aryobarzan

SGU 456

Jun 13th, 2011
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. double pay(double x,double month,double percent,double total)
  6. {
  7.     double paid=0;
  8.     for(int i=0;i<month;++i)
  9.     {
  10.         double ai=(percent/100)*(total-paid);
  11.         double bi=x-ai;
  12.         paid+=bi;
  13.     }
  14.     return paid;
  15. }
  16.  
  17. int main()
  18. {
  19.     double s,m,p;
  20.     cin>>s>>m>>p;
  21.     double up=100*s;
  22.     double down=0;
  23.     while(up-down>1e-7)
  24.     {
  25.         double mid=(up+down)/2;
  26.         double total_p=pay(mid,m,p,s);
  27.         if(total_p>s)
  28.             up=mid;
  29.         else
  30.             down=mid;
  31.     }
  32.     cout<<fixed<<setprecision(6)<<(up+down)/2<<endl;
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement