1014. Product of Digits

11 篇文章 0 订阅
1014. Product of Digits
Time 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;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值