Count all N digit numbers whose digits are multiple of X | C ++ program for the above approach ; Function to calculate x ^ n using binary - exponentiation ; Stores the resultant power ; Stores the value of x ^ ( n / 2 ) ; Function to count all N - digit numbers whose digits are multiples of x ; Count all digits which are multiples of x ; Check if current number is a multiple of X ; Increase count of multiples ; Check if it 's a 1 digit number ; Count the total numbers ; Return the total numbers ; Driver Code ; Given N and X ; Function Call
#include <stdio.h> NEW_LINE #define ll  long long NEW_LINE ll power ( ll x , ll n ) { ll temp ; if ( n == 0 ) return 1 ; temp = power ( x , n / 2 ) ; if ( n % 2 == 0 ) return temp * temp ; else return x * temp * temp ; } ll count_Total_Numbers ( ll n , ll x ) { ll total , multiples = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) { if ( i % x == 0 ) multiples ++ ; } if ( n == 1 ) return multiples ; total = ( multiples - 1 ) * power ( multiples , n - 1 ) ; return total ; } int main ( ) { ll N = 1 , X = 3 ; printf ( " % lld ▁ " , count_Total_Numbers ( N , X ) ) ; return 0 ; }