栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C. Drazil and Factorial【1400 / 构造】

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C. Drazil and Factorial【1400 / 构造】


https://codeforces.com/problemset/problem/515/C
题目给的意思就是不包含0,1 且 f(x)==f(a) 且x要尽量的大。
自己的垃圾模拟做法:

#include
using 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!

故代码如下:

#include
using 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<
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/352829.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号