Smallest number whose sum of digits is square of N | C ++ implementation of the above approach ; Function to return smallest number whose sum of digits is n ^ 2 ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int smallestNum ( int n ) { cout << pow ( 10 , n * n / 9 ) << endl ; return ( n * n % 9 + 1 ) * pow ( 10 , n * n / 9 ) - 1 ; } int main ( ) { int n = 4 ; cout << smallestNum ( n ) ; return 0 ; }