Check if a given number divides the sum of the factorials of its digits | C ++ implementation of the approach ; Function that returns true if n divides the sum of the factorials of its digits ; To store factorials of digits ; To store sum of the factorials of the digits ; Store copy of the given number ; Store sum of the factorials of the digits ; If it is divisible ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPossible ( int n ) { int fac [ 10 ] ; fac [ 0 ] = fac [ 1 ] = 1 ; for ( int i = 2 ; i < 10 ; i ++ ) fac [ i ] = fac [ i - 1 ] * i ; int sum = 0 ; int x = n ; while ( x ) { sum += fac [ x % 10 ] ; x /= 10 ; } if ( sum % n == 0 ) return true ; return false ; } int main ( ) { int n = 19 ; if ( isPossible ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }