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

get WA at test 41
Posted by Fahim 1 Dec 2023 18:13
#include<bits/stdc++.h>
using namespace std;
bool isPrime(int n)
{
    if(n!=2&&n%2==0)return false;
    if(n<2)return false;
    for(int i=3;i<=sqrt(n);i+=2)
    {
        if(n%i==0)return false;
    }
    return true;
}
int main()
{
    int n;
    cin>>n;
    int x=9,r;
    if(n==1)cout<<1<<endl;
    else if(n==0)cout<<10<<endl;
else{
    vector<int>v;
    while(1)
    {
        if(n%x==0)
        {
           if(isPrime(n)==true)
           {
            if(n>9){cout<<-1<<endl;return 0;}
           }
           n=n/x;
           if(x==1)break;
           v.push_back(x);
        }
        else
        {
            x--;
        }

    }
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i];
    }
    cout<<endl;
}
}