Advertisement
IISergeyII

Untitled

May 24th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <math.h>
  5. #include <vector>
  6. #include <fstream>
  7.  
  8. using namespace std;
  9.  
  10. int getSize(int x) {
  11.     int l = 0;
  12.     while (x > 0) {
  13.         l++;
  14.         x /= 10;
  15.     }
  16.  
  17.     return l;
  18. }
  19.  
  20. int countAmount(long long N, long long x) {
  21.  
  22.     int l = getSize(x);
  23.     int p = pow(10, l);
  24.     if (p % 10 != 0) p++;
  25.  
  26.     int myAns = 0;
  27.     myAns = N/p;
  28.     if ( N % p > x)  {
  29.         myAns++;
  30.     }
  31.  
  32.     return myAns;
  33. }
  34.  
  35. int main()
  36. {
  37.  
  38.     long long k = 0;
  39.     long long M, N;
  40.     cin >> M >> N;
  41.  
  42.     int t = pow(10, N);
  43.     if (t % 10 != 0) t++;
  44.  
  45.     int d = pow(2, N);
  46.     if (d % 2 != 0) d--;
  47.  
  48.     //cout << d << endl;
  49.     long long ans = 0;
  50.  
  51.     for (int i = d; i < t; i+=d) {
  52.             ans += countAmount(M, i);
  53.             //cout << "i " << i << " ans " << ans << endl;
  54.         }
  55.  
  56.     cout << ans;
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement