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

Why WA
Posted by faust 22 Sep 2002 14:26
#include <iostream.h>

int main(void)
{
    unsigned long N, Q = 0;
    long pow = 10;

    cin >> N;

    if(N == 0)
    {
        cout << 10;
        return 0;
    };

    for(long i = 9 ; i > 1 ; --i)
    {
        while(!(N % i))
        {
            if(Q == 0)
            {
                Q = i;
                N /= i;
            }else
            {
                Q += i * pow;
                pow *= 10;
                N /= i;
            };
        };
    };

    if( N != 1)
        cout << -1;
    else
        cout << Q;

    return 0;
};