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

wa#5 why? help!
Posted by mark_ivanov 24 Nov 2011 18:42
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char** argv){
    long long int n;
    cin>>n;
    vector<char> v;
    if(n == 1){
        cout<<1;
        return 0;
    }
    else if(n == 0){
        cout<<10;
        return 0;
    }
    int cur = 9;
    while(n!=1){
        bool flag = false;
        for(; cur>=2; --cur){
             if(n/cur*cur==n){
                flag = true;
                v.push_back(cur);
                n = n/cur;
                cur = 9;
            }
        }
        if(!flag){
            cout<<-1;
            return 0;
        }
    }
    sort(v.begin(), v.end());
    long long int a = 0;
    for(int i = 0; i<v.size(); i++){
        a = a*10 + v.at(i);
    }
    cout<<a;
}