515C - Drazil and Factorial
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.
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 a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
4
1234
33222
3
555
555
In the first case, 
题意:给你一个数a,F(a)是n位数,要你找一个数k,使得F(k)=F(a)且k中的每一位数不能为0或1
直接看代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string a;
cin>>n>>a;
int num[4],i;
for(i=0;i<4;i++){
num[i]=0;
}
for(i=0;i<n;i++){
int k=a[i]-48;
if(k==2) num[0]++;
else if(k==3){
num[1]++;
}
else if(k==4){
num[0]=num[0]+2;
num[1]++;
}
else if(k==5){
num[2]++;
}
else if(k==6){
num[1]++;
num[2]++;
}
else if(k==7){
num[3]++;
}
else if(k==8){
num[0]=num[0]+3;
num[3]++;
}
else if(k==9){
num[0]=num[0]+1;
num[1]=num[1]+2;
num[3]++;
}
}
for(i=3;i>=0;i--){
for(int j=0;j<num[i];j++){
if(i==3) cout<<7;
else if(i==2) cout<<5;
else if(i==1) cout<<3;
else if(i==0) cout<<2;
}
}
cout<<endl;
return 0;
}

浙公网安备 33010602011771号