Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdint>
- int count5(long long n) {
- int answer = 0;
- while (n > 0) {
- answer += (n % 10 == 5);
- n /= 10;
- }
- return answer;
- }
- long long count (long long n) {
- if (n < 4) {
- return 0;
- } else if (n <= 9) {
- return 1;
- } else if (n % 10 == 9) {
- return (n+1) / 10 + 10 * count((n-9) / 10);
- } else {
- return count5(n) + count(n-1);
- }
- }
- int main() {
- long long n;
- scanf("%lld", &n);
- printf("%lld", count(n));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement