Ural 1014 The Product of Digits

Ural 1014 The Product of Digits

这题想错了,就是把N分解了,如果素因子有大于等于10的就不行了,想复杂了

#include < iostream >
using   namespace  std;
int  a[ 10 ] = { 0 };
int  main()
{
    
int  n,i;
    cin
>> n;
    
if (n == 0 ){cout << 10 << endl; return   0 ;}
    
else   if (n == 1 ){cout << 1 << endl;  return   0 ;}
    
int  p = n;
    
for (i = 9 ; i >= 2 ; )
    {
        
if (p % i == 0 ){a[i] ++ ; p /= i;}
        
else  i -- ;
    }
    
if (p != 1 ){ cout <<- 1 << endl;  return   0 ; }
    
for (i = 2 ; i <= 9 ; i ++ )
    
for ( int  j = 1 ; j <= a[i]; j ++ )
      cout
<< i;
    cout
<< endl;
    
    system(
" pause " );
    
return   0 ;
}

你可能感兴趣的:(Ural 1014 The Product of Digits)