本文主要是介绍1014. Product of Digits,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1014. Product of DigitsTime limit: 1.0 second
Memory limit: 64 MB
Your task is to find the minimal positive integer number Q so that the product of digits of Q is exactly equal to N.
Input
The input contains the single integer number N (0 ≤ N ≤ 109).
Output
Your program should print to the output the only number Q. If such a number does not exist print −1.
Sample
input
10
output
25
Problem Source: Ural State University Internal Contest '99 #2
就是求因式分解的变形,开始的时候用递归求,是可以的,后来发现这个问题我在几年前很熟悉呢,竟然都抽离不出来,心塞。然后提交的时候发生了一件由cout<<endl;引发的血案,一直不过,后来发现在为负数时,打出两个回车竟然就不过,伤心
#include<iostream>
using namespacestd;
int a[100];
int main(){
int N;
cin>>N;
if(N==0){
cout<<10<<endl;
return0;
}
if(N<10){
cout<<N<<endl;
return0;
}
int count =0;
for(int i =9 ; i >= 2 && N!=1;i--){
while (N%i==0&& N!=1) {
a[++count] = i;
N = N/i;
}
}
if(N!=1){
cout<<"-1"<<endl;
return0;
}
for(int i = count ; i >=1 ; i--){
cout<<a[i];
}
cout<<endl;
return0;
}
这篇关于1014. Product of Digits的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!