CF_292_C_Drazil and Factorial_数学

我妈刚才又骂我。


题意:

定义正整数x的F(x)值是x的各个数字的阶乘的乘积,如 

给出一个正整数a,求最大的正整数x,满足以下条件:

1. F(x) = F(a)

2. 组成x的数字不包括0和1


Input

The first line contains an integer n (1 ≤ n ≤ 15) — the number of digits in a.

The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.

Output

Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.


首先要分解出的数字数量最多,其次要尽量大,然后按从高到低排序。这题乍一看不知道怎么破,但是除了0、1一共就八个数字,每个数字想一下怎么分解最好就行了,这样一搞就很水了。

ACM和程序都是解决实际问题,没必要每个题都用系统的数学证明,枚举就好。


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define mxn 20
int n;
char a[mxn];
int b[mxn<<2],cnt;
int main(){
    while(scanf("%d",&n)!=EOF){
        getchar();
        cnt=0;
        for(int i=0;i<n;++i)    a[i]=getchar();
        for(int i=0;i<n;++i){
            if(a[i]=='0'||a[i]=='1')    continue;
            else if(a[i]=='2'||a[i]=='3'||a[i]=='5'||a[i]=='7')
                b[cnt++]=a[i]-'0';
            else if(a[i]=='4'){
                b[cnt++]=3;
                b[cnt++]=2;
                b[cnt++]=2;
            }
            else if(a[i]=='6'){
                b[cnt++]=3;
                b[cnt++]=5;
            }
            else if(a[i]=='8'){
                b[cnt++]=2;
                b[cnt++]=2;
                b[cnt++]=2;
                b[cnt++]=7;
            }
            else if(a[i]=='9'){
                b[cnt++]=3;
                b[cnt++]=3;
                b[cnt++]=2;
                b[cnt++]=7;
            }
        }
        sort(b,b+cnt);
        for(int i=cnt-1;i>=0;--i)
            printf("%d",b[i]);
        puts("");
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值