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

My code is getting Wrong answer 5 despite getting correct answers for all possible cases.
Posted by tdnnojtupbkmuhehvb 14 Oct 2022 13:23
Whats wrong with anything here?
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ui=unsigned int;
int main() {
    //ios::sync_with_stdio(0);
    //cin.tie(0);
    ll n;cin>>n;
    if(!n){
        cout<<10;
        return 0;
    }
    else if(n<10){
        cout<<n;
        return 0;
    }
    vector<int>v;
    ll l=n;
    for(bool q=1;q;){
        q=0;
        for(ll i=9;i>1;i--){
            if(l%i==0){
                l/=i;
                v.push_back(i);
                q=1;

            }
        }
    }
    v.push_back(l);
    sort(v.begin(),v.end());
    if(v[0]==1)for(int i=1;i<v.size();i++)cout<<v[i];
    else cout<<-1;
    return 0;
}
Re: My code is getting Wrong answer 5 despite getting correct answers for all possible cases.
Posted by tdnnojtupbkmuhehvb 14 Oct 2022 13:40
Ok later I figured out that instead of dividing by all the numbers consecutively, dividing by the current factor between 2 to 9 repeatedly until it isn't a factor provides the fewest digits. For example, input 1000000 gives 245555558 in the above program, whereas 2 and 4 could be replaced by 8 for better result.

Edited by author 14.10.2022 13:41