CodeForces 515C. Drazil and Fa
2015-06-10 11:51
411 查看
想了一段时间,最后从纯数学的角度上解决的。
首先读入这个串,因为素数是不可以被分解的,所以只要是素数,就整个的保留下来,如果是合数就分解成素数。
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
Output
Input
Output
Hint
In the first case,
首先读入这个串,因为素数是不可以被分解的,所以只要是素数,就整个的保留下来,如果是合数就分解成素数。
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; }
相关文章推荐
- hihoCoder#1038 : 01背包
- 微信公众平台开发最佳实践(第2版)
- HTTP协议详解
- 修改Android启动画面
- 找回误删除的文件
- Java的内存机制
- 【HTML+CSS】(1)基础语法
- 事件绑定
- 在imp数据库时报错1045
- .net接口作用
- PMC云计算大会再出击 携众厂商高歌猛进
- android Dialog给Activity 传参
- UI控件问题和XCode编译警告和错误解决方法集锦 (持续更新ing)
- 让Git 更好的配置
- c++中的 extern "C"用法
- 方块大动员登陆iOS和Android平台,扫码就可立即体验超流畅的俄罗斯方块手游
- 多线程-NSOperationQueue
- Android快速开发之appBase——(3).详解IHolder和IData
- andrdoid内置视频文件
- 《mysql 必知必会》学习笔记(三)