CodeForces 515C. Drazil and Fa

本文介绍了一个数学游戏,玩家需要根据给定的数字串构造一个不含0和1的最大数值。通过将输入数字分解为素数因子并重新组合,最终得到满足条件的最大整数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

想了一段时间,最后从纯数学的角度上解决的。

首先读入这个串,因为素数是不可以被分解的,所以只要是素数,就整个的保留下来,如果是合数就分解成素数。

4!被分解为3!*2!*2!

6! = 5! * 3!

8! = 7! * 2! * 2! * 2!

9! = 7! * 3! * 3! * 2!

最后再用sort()反向排一下序,输出即可,碰到0和1跳过不管即可。

Description

Drazil is playing a math game with Varda.

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

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.  = .

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.

Sample Input

Input
4
1234
Output
33222
Input
3
555
Output
555

Hint

In the first case, 



#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<string.h>

using namespace std;

string str1;
string str2;

bool cmp(const char &a,const char &b)
{
    return a > b;
}

int main()
{
//    int str2[20];
//    memset(str2 , 0 , sizeof(str2));
    int n ;
    cin>>n>>str1;
    for(int i = 0 ; i < n ; i++)
    {
//        if(str[i] == '0')
//        {
//            cout<<'0'<<endl;
//            break;
//        }
        if(str1[i] == '4')
            str2 += "223";
        else if(str1[i] == '6')
            str2 += "53";
        else if(str1[i] == '8')
            str2 += "7222";
        else if( str1[i] == '9')
            str2 += "7332";
        else if(str1[i] == '1');
        else if(str1[i] == '0');
            else
            str2 += str1[i];
    }
//    cout<<str2<<endl;
    sort(str2.begin(), str2.end() , cmp);
    cout<<str2<<endl;
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值