Guest User

Untitled

a guest
May 31st, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <bits\stdc++.h>
  2. using namespace std;
  3.  
  4. int t;
  5. void pr(long long a, int sz){
  6.     int aa = a;
  7.     while(a > 0){
  8.         a /= 10;
  9.         sz--;
  10.     }
  11.     for(int i = 0; i < sz; ++i){
  12.         printf("0");
  13.     }
  14.     if(aa != 0)
  15.     printf("%I64d", aa);
  16. }
  17. int main()
  18. {
  19.     double l, r;
  20.     int k;
  21.     while(cin >> l >> r >> k && k != -1)
  22.     {
  23.         t++;
  24.         long long mantisa = k * log10(r);
  25.         double cur = 0;
  26.         for(double it = l; it <= r; ++it)
  27.         {
  28.             cur += pow(10.0, k * log10(it) - (double)mantisa);
  29.         }
  30.         while(cur >= 1)
  31.         {
  32.             cur /= 10;
  33.             mantisa++;
  34.         }
  35.         if(r != 0){
  36.             printf("Case ");
  37.             pr(t, 4);
  38.             printf(": %.6fe", cur);
  39.             pr(mantisa, 10);
  40.             printf("\n");
  41.         }
  42.         else{
  43.             mantisa++;
  44.             printf("Case ");
  45.             pr(t, 4);
  46.             printf(": %.6fe", cur);
  47.             pr(mantisa, 10);
  48.             printf("\n");
  49.         }
  50.     }
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment