my solution in c++ 0.031 s.
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
inline bool isprime(long a)
{
if(a==1)return false;
if(a==2)return true;
if(a%2==0)return false;
for(int i=3;i<sqrt(a);i+=2)
{
if(a%i==0)return false;
}
return true;
}
int main()
{
string a;
long n;
int d=1;
cin>>n;
if(n==0)cout<<"10"<<endl;
else if(n==1)cout<<"1"<<endl;
else{
if(isprime(n) && n>10)d=0;
else
{
int gamyop=9;
while(n!=1)
{
if(n%gamyop==0)
{
a+=(gamyop+'0');
n/=gamyop;
if(isprime(n) && n>10){d=0;break;}
}
else
{
gamyop--;
}
}
}
sort(a.begin(),a.end());
if(d==1)cout<<a<<endl;
else cout<<"-1"<<endl;
}
return 0;
}
I have this problem too!!!
All test, what i see is correct;
I use unsigned long;
May be it consist false;
What I doing wrong?
Edited by author 05.04.2006 14:23