标签:素数相关
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. F(x)=F(a) .
Help friends find such number.
TimeLimit(ms):2000
MemoryLimit(MB):256
n∈[1,15] (the number of digits in a)There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.
考虑数a的每个digit,0和1忽略,其余若是素数则无法拆分,即
2!=2! ,3!=3! ,5!=5! ,7!=7! ;非素数可以拆分:
4!=4×3!=2!×2!×3!
6!=6×5!=3!×5!
8!=2!×2!×2!×7!
9!=2!×3!×3!×7! 按此维护答案即可
TimeComplexity:O(n)
MemoryComplexity:O(n)
//Hello. I‘m Peter.
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<cctype>
#include<ctime>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int uin;
#define peter cout<<"i am peter"<<endl
#define input freopen("data.txt","r",stdin)
#define randin srand((unsigned int)time(NULL))
#define INT (0x3f3f3f3f)*2
#define LL (0x3f3f3f3f3f3f3f3f)*2
#define gsize(a) (int)a.size()
#define len(a) (int)strlen(a)
#define slen(s) (int)s.length()
#define pb(a) push_back(a)
#define clr(a) memset(a,0,sizeof(a))
#define clr_minus1(a) memset(a,-1,sizeof(a))
#define clr_INT(a) memset(a,INT,sizeof(a))
#define clr_true(a) memset(a,true,sizeof(a))
#define clr_false(a) memset(a,false,sizeof(a))
#define clr_queue(q) while(!q.empty()) q.pop()
#define clr_stack(s) while(!s.empty()) s.pop()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define dep(i, a, b) for (int i = a; i > b; i--)
#define repin(i, a, b) for (int i = a; i <= b; i++)
#define depin(i, a, b) for (int i = a; i >= b; i--)
#define pi 3.1415926535898
#define eps 1e-9
#define MOD 1000000007
#define MAXN (1<<10)+10
#define N 110
#define M
int n;
string s,ans,digit[N];
int main(){
digit[0]=digit[1]="";
digit[2]="2";
digit[3]="3";
digit[4]="223";
digit[5]="5";
digit[6]="35";
digit[7]="7";
digit[8]="2227";
digit[9]="2337";
cin>>n;
cin>>s;
ans.clear();
rep(i,0,n){
ans+=digit[s[i]-‘0‘];
}
sort(ans.begin(),ans.end());
depin(i,slen(ans)-1,0){
cout<<ans[i];
}
cout<<endl;
}
标签:素数相关
原文地址:http://blog.csdn.net/uestc_peterpan/article/details/43875129