// C++ code to implement the approach
#include <bits/stdc++.h>
using namespace std;
// Function for generating largest
// N-digit number in K-steps.
int largestNDigitNumber(int N, int currentStep,
int K, int X, int Y,
int currentValue)
{
// Further processing is useless
// ifcCurrent value already becomes equal
// to largest N-digit number that
// can be generated
if (currentValue == pow(10, N) - 1)
return currentValue;
// Return 0 steps taken is greater than K
// and also if N or K equal to Zero.
if (currentStep > K || N < 1 || K < 1)
return 0;
// currentValue exceeds maxValue,
// so there is no need to
// keep searching on that branch.
if (currentValue >= pow(10, N))
return 0;
// Recursive calls
int result2 = largestNDigitNumber(
N, currentStep + 1, K, X, Y,
currentValue + X);
int result1 = largestNDigitNumber(
N, currentStep + 1, K, X, Y,
currentValue * Y);
// If both the results are zero
// it means maximum is reached.
if (result1 == 0 && result2 == 0)
return currentValue;
// Checking for maximum of the two results.
return result1 > result2 ? result1 : result2;
}
// Driver code
int main()
{
int N = 2, K = 10, X = 2, Y = 3;
int largest = largestNDigitNumber(
N, 0, K, X, Y, 0);
// Checking whether the returned result
// is a N-digit number or not.
if (largest < pow(10, (N - 1))) {
cout << ("-1");
}
else
cout << largest;
return 0;
}