Find The Occurrences of Digit D in The Range (0..n) - GeeksforGeeks
Find The Occurrences of Digit D in The Range (0..n) - GeeksforGeeks
n] - GeeksforGeeks
Input : n = 25
d = 2
Output : 9
The occurrences are 2, 12, 20, 21
22 (Two occurrences), 23, 24, 25
Input : n = 25
d = 3
Output :3
The occurrences are 3, 13, 23
Input : n = 32
d = 3
Output : 6
The occurrences are 3, 13, 23, 30, 31, 32
Recommended Practice
DSAThis
Practice Mathematical
solution is basedAlgorithm
on theMathematical
modularity Algorithms Pythagorean
of each digit at itsTriplet Fibonacci
position in theNumber E
number.
C++
#include <iostream>
#include <math.h>
https://www.geeksforgeeks.org/find-the-occurrences-of-y-in-the-range-of-x/ 1/12
13/04/2024, 13:07 Find the occurrences of digit d in the range [0..n] - GeeksforGeeks
int main()
{
int N, X;
N = 1000;
X = 0;
cout << myCountX(N, X);
return 0;
https://www.geeksforgeeks.org/find-the-occurrences-of-y-in-the-range-of-x/ 2/12