P18958 [GeeksforGeeks] Count the numbers2359
普及-
题目描述

Given a number N, count the numbers from 1 to N which comprise of digits only from set {1, 2, 3, 4, 5}.
Example 1:
Input:
N = 20
Output: 10
Explanation: The numbers whose digits
are from the given set are:
1, 2, 3, 4, 5, 11, 12, 13, 14, 15.
Example 2:
Input:
N = 100
Output: 30
Your Task:
You don't need to read input or print anything. Your task is to complete the function countNumbers() which takes the integer n as input parameter and returns an integer denoting the answer.
Expected Time Complexity: O(N * number of digits in an integer)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 10^{5}

输入格式

见题面

输出格式

见题面

样例输入
N = 20
样例输出
10