Smallest number whose product with N has sum of digits equal to that of N | C ++ program for the above approach ; Function to find the minimum integer having sum of digits of a number multiplied by n equal to sum of digits of n ; Initialize answer ; Find sum of digits of N ; Multiply N with x ; Sum of digits of the new number ; If condition satisfies ; Print answer ; Driver Code ; Function call
#include <iostream> NEW_LINE using namespace std ; void find_num ( string n ) { int ans = 0 ; int sumOfDigitsN = 0 ; for ( int c = 0 ; c < n . length ( ) ; c ++ ) { sumOfDigitsN += n - '0' ; } int x = 11 ; while ( true ) { int newNum = x * stoi ( n ) ; int tempSumDigits = 0 ; string temp = to_string ( newNum ) ; for ( int c = 0 ; c < temp . length ( ) ; c ++ ) { tempSumDigits += temp - '0' ; } if ( tempSumDigits == sumOfDigitsN ) { ans = x ; break ; } x ++ ; } cout << ans << endl ; } int main ( ) { string N = "3029" ; find_num ( N ) ; return 0 ; }