ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1014. Product of Digits

Very simple solution in C++
Posted by Andreas 20 Dec 2013 03:57
#include <iostream>

long long getQforN(long long N)
{
    if (N == 0)
        return 10;
    else if (N == 1)
        return 1;

    long long Q = 0;
    long long p = 1;

    for(long long div = 9; div > 1; --div)
    {
        while( (N%div) == 0)
        {
            Q += p * div;
            p = p * 10;
            N /= div;
        }
    }

    return (N == 1) ? Q : -1;
}

int main(int argc, char **argv)
{
    long long N;
    std::cin >> N;
    std::cout << getQforN(N) << std::endl;
    return 0;
}

Edited by author 20.12.2013 03:59
Re: Very simple solution in C++
Posted by Mano 19 Sep 2015 18:02


Edited by author 19.09.2015 18:03
Re: Very simple solution in C++
Posted by Umidbek(TUIT Urgench) 11 Nov 2016 11:54
Good idea. Thank you !!!