Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <fstream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("eureni.in");
  7. ofstream fout("eureni.out");
  8.  
  9. unsigned short int i,e,k,n,l,d;
  10. int S;
  11. double a[12];
  12.  
  13. int main()
  14. {
  15.  
  16.     fin >> S >> n >> e;
  17.  
  18.     k=n;
  19.  
  20.     for (i=1;i<=n+1;i++)
  21.     {
  22.         a[i]=pow(e,k);
  23.         k--;
  24.     }
  25.  
  26.     i=1;
  27.  
  28.     while(S!=0)
  29.     {
  30.         if(a[i]<=S)
  31.         {
  32.             d++;
  33.             l++;
  34.             S-=a[i];
  35.             if(S==0) fout<< a[i] << " " << l << endl;
  36.         }
  37.         else
  38.         {
  39.             if (l!=0) fout << a[i] << " " << l << endl;
  40.             l=0;
  41.             i++;
  42.         }
  43.     }
  44.  
  45.     fout << d << endl;
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement