HTML & JS
// C++ program to find Seed of a number
#include <bits/stdc++.h>
using namespace std;
const int MAX = 10000;

int prodDig[MAX];

// Stores product of digits of x in prodDig[x]
int getDigitProduct(int x)
{
    // If x has single digit
    if (x < 10)
      return x;

    // If digit product is already computed
    if (prodDig[x] != 0)
       return prodDig[x];

    // If digit product is not computed before.
    int prod = (x % 10) * getDigitProduct(x/10);

    return (prodDig[x] = prod);
}

// Prints all seeds of n
void findSeed(int n)
{
    // Find all seeds using prodDig[]
    vector<int> res;
    for (int i=1; i<=n/2; i++)
        if (n % i == 0 && i*getDigitProduct(i) == n)
            res.push_back(i);

    // If there was no seed
    if (res.size() == 0)
    {
        cout << "NO seed exists\n";
        return;
    }

    cout << "Seeds are : ";
    for (int i=0; i<res.size(); i++)
        cout << res[i] << endl;
}

// Driver code
int main()
{
    long long int n = 138;
    findSeed(n);
    return 0;
}

Generated URL:

Output:

Seeds are : 23
Report Bug