Count N | C ++ program for the above approach ; Function to count N - digit numbers such that each position is divisible by the digit occurring at that position ; Stores the answer . ; Iterate from indices 1 to N ; Stores count of digits that can be placed at the current index ; Iterate from digit 1 to 9 ; If index is divisible by digit ; Multiply answer with possible choices ; Driver Code ; Given Input ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int mod = 1e9 + 7 ; void countOfNumbers ( int N ) { int ans = 1 ; for ( int index = 1 ; index <= N ; ++ index ) { int choices = 0 ; for ( int digit = 1 ; digit <= 9 ; ++ digit ) { if ( index % digit == 0 ) { ++ choices ; } } ans = ( ans * 1LL * choices ) % mod ; } cout << ans << endl ; } int main ( ) { int N = 5 ; countOfNumbers ( N ) ; return 0 ; }