Advertisement
dmkozyrev

460_error.cpp

Aug 14th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstdint>
  3.  
  4. int count5(long long n) {
  5.     int answer = 0;
  6.     while (n > 0) {
  7.         answer += (n % 10 == 5);
  8.         n /= 10;
  9.     }
  10.     return answer;
  11. }
  12.  
  13. long long count (long long n) {
  14.     if (n < 4) {
  15.         return 0;
  16.     } else if (n <= 9) {
  17.         return 1;
  18.     } else if (n % 10 == 9) {
  19.         return (n+1) / 10 + 10 * count((n-9) / 10);
  20.     } else {
  21.         return count5(n) + count(n-1);
  22.     }
  23. }
  24.  
  25.  
  26. int main() {
  27.     long long n;
  28.     scanf("%lld", &n);
  29.     printf("%lld", count(n));
  30.      
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement