Smallest x such that 1 * n , 2 * n , ... x * n have all digits from 1 to 9 | CPP program to find x such that 1 * n , 2 * n , 3 * n ... x * n have all digits from 1 to 9 at least once ; Returns smallest value x such that 1 * n , 2 * n , 3 * n ... x * n have all digits from 1 to 9 at least once ; taking temporary array and variable . ; iterate till we get all the 10 digits at least once ; checking all the digits ; driver function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int smallestX ( int n ) { int temp [ 10 ] = { 0 } ; if ( n == 0 ) return -1 ; int count = 0 , x = 0 ; for ( x = 1 ; count < 10 ; x ++ ) { int y = x * n ; while ( y ) { if ( temp [ y % 10 ] == false ) { count ++ ; temp [ y % 10 ] = true ; } y /= 10 ; } } return x - 1 ; } int main ( ) { int n = 5 ; cout << smallestX ( n ) ; return 0 ; }