https://codeforces.com/problemset/problem/515/C
题目给的意思就是不包含0,1 且 f(x)==f(a) 且x要尽量的大。
自己的垃圾模拟做法:
#includeusing namespace std; typedef long long int LL; bool check(int x) { for(int i=2;i<=x/i;i++) if(x%i==0) return true; return false; } void solve(LL x) { int a[15]={0};//分解阶乘,统计所有的数字出现的个数 while(x) { int temp=x%10; for(int i=2;i<=temp;i++) a[i]++; x/=10; } int index=0;//找到最大的阶乘数字 for(int i=9;i>=2;i--) if(a[i]) {index=i;break;} for(int i=index;i>=2;i--) { while(a[i]>a[i+1]&&check(i))//如果是合数 //在满足上一个阶乘的条件下,将多余的尽可能的分解 { int s=i; for(int j=2;j<=s/j;j++) while(s%j==0) a[j]++,s/=j; if(s!=1) a[s]++; a[i]--; } } int ans[300]={0}; for(int i=0;i>n>>x; solve(x); return 0; }
其实你会发现可以直接替换
- 2!=2!
- 3!=3!
- 4!=3!2!2!
- 5!=5!
- 6!=5!3!
- 7!=7!
- 8!=7!2!2!2!
- 9!=7!3!3!2!
故代码如下:
#includeusing namespace std; string s[15]={"","","2","3","322","5","53","7","7222","7332"}; int main(void) { long long int n,x; cin>>n>>x; string ans; while(x) ans+=s[x%10],x/=10; sort(ans.begin(),ans.end()); reverse(ans.begin(),ans.end()); cout<



