Given a number N. We have to find the count of such numbers that can be formed using digit 3 and 4. So if N = 6, then the numbers will be 3, 4, 33, 34, 43, 44.
We can solve this problem if we look closely, for single digit number it has 2 numbers 3 and 4, for digit 2, it has 4 numbers 33, 34, 43, 44. So for m digit numbers, it will have 2m values.
Example
#include<iostream>
#include<cmath>
using namespace std;
long long countNumbers(int n) {
return (long long)(pow(2, n + 1)) - 2;
}
int main() {
int n = 3;
cout << "Number of values: " << countNumbers(n);
}Output
Number of values: 14