Advertisement
IISergeyII

Untitled

May 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 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.     if (x == 0) {
  23.         return N/10;
  24.     }
  25.  
  26.     int l = getSize(x);
  27.     int p = pow(10, l);
  28.     if (p % 10 != 0) p++;
  29.  
  30.     int myAns = 0;
  31.     myAns = N/p;
  32.     if ( N % p >= x)  {
  33.         myAns++;
  34.     }
  35.  
  36.     return myAns;
  37. }
  38.  
  39. int main()
  40. {
  41.  
  42.     long long k = 0;
  43.     long long M, N;
  44.     cin >> M >> N;
  45.  
  46.     int t = pow(10, N);
  47.     if (t % 10 != 0) t++;
  48.  
  49.     int d = pow(2, N);
  50.     if (d % 2 != 0) d--;
  51.  
  52.  
  53.     //cout << d << endl;
  54.     long long ans = 0;
  55.  
  56.     for (int i = 0; i < t; i+=d) {
  57.             ans += countAmount(M, i);
  58.             cout << "i " << i << " ans " << ans << endl;
  59.         }
  60.  
  61.     cout << ans;
  62.  
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement