Div2 515 C

C. Drazil and Factorial

Drazil is playing a math game with Varda.

Let’s define img for positive integer x as a product of factorials of its digits. For example, img.

First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:

\1. x doesn’t contain neither digit 0 nor digit 1.

\2. img = img.

Help friends find such number.

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.

Examples

input

4
1234

output

33222

input

3
555

output

555
Note

In the first case, img

Part1 简述题目

给出一个字符 s s s ,接着通过 F F F函数对字符串上的每一位数字进行阶乘相乘,最终得到一个数,我们设为 x x x

同样找到一个字符数,通过 F F F函数,得到同样的 x x x,求最新的字符数的最大正数

限制条件

  1. 最大正数中不包含0和1
  2. F ( x ) = F ( a ) F(x) = F(a) F(x)=F(a)

Part2 解题思路

题外话、刚开始做的时候是按照拆分偶数做的,后来发现 9 = 3 ∗ 3 9 = 3 * 3 9=33卡我半天。。。。

为了让最终的字符数尽可能的大,我们应该将原来的字符串拆分为更多位数

考虑对谁进行拆分?

本题中我们应该对10以内的非质数进行拆分

拿指数5举例,我们将其拆分为 5 ∗ 4 ! 5 * 4! 54! ,这个5是无法通过别的数相乘得到,所以说 5 ! 5! 5!需要保持原样不变

如果 s [ i ] = 2 s[i] = 2 s[i]=2,我们应该将其拆分为 2 ! = 2 ! 2! = 2! 2!=2!

如果 s [ i ] = 4 s[i] = 4 s[i]=4,我们应该将其拆分为 4 ! = 3 ! ∗ 2 ! 4! = 3! *2! 4!=3!2!

如果 s [ i ] = 6 s[i] = 6 s[i]=6,我们应该将其拆分为 6 ! = 5 ! ∗ 3 ! 6! = 5! * 3! 6!=5!3!

如果 s [ i ] = 8 s[i] = 8 s[i]=8,我们应该将其拆分为 8 ! = 7 ! ∗ 2 ! ∗ 2 ! ∗ 2 ! 8! = 7! * 2! *2! * 2! 8!=7!2!2!2!

如果 s [ i ] = 9 s[i] = 9 s[i]=9,我们应该将其拆分为 9 ! = 7 ! ∗ 3 ! ∗ 3 ! ∗ 2 ! 9! = 7! * 3! * 3! *2! 9!=7!3!3!2!

Part3 C o d e Code Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) begin(x),end(x)
#define str string

void ins(int v,vector<int> &a) {
    if(v == 2) a.push_back(2);
    else if(v == 4) {a.push_back(2); a.push_back(2); a.push_back(3);}
    else if(v == 6) {a.push_back(3); a.push_back(5);}
    else {a.push_back(2);a.push_back(2);a.push_back(2); a.push_back(7);}

}

inline void solve() { 
    int n; str m; cin >> n >> m;
    vector<int> a;

    for(int i{};i < n;i++) {
        int t = m[i] - '0';
        if(t == 0 || t == 1) continue;
        
        if(t % 2 == 0) ins(t,a);
        else if(t == 9) {
            a.push_back(3); a.push_back(3); a.push_back(7); a.push_back(2);
        }
        else a.push_back(t);

        
    }

    sort(all(a),[&](int u,int v) {
        return u > v;
    });

    for(auto it : a) cout << it;
    cout << endl;

    
}

int main(){
    // freopen("input.txt","r",stdin);
    // int t; cin >> t;
    // while(t--) solve();

    solve();
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值