Codeforces #292C. Drazil and Factorial 数学

题目

题目链接:http://codeforces.com/problemset/problem/515/C

题目来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105944#problem/D

简要题意: F(n) 为各位的阶乘之积,求一最大的 n,F(n)=F(n)

题解

数学题,分情况去讨论或者一步步分解。

首先对于质数或 1 <script type="math/tex" id="MathJax-Element-3">1</script>的阶乘是无法分解的。

能够分解成越多数字越好,然后就去分解就行了,都是分解成若干质数。

代码

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
// head
int cnt[15];
char s[25];

void add(int x) {
    if (x == 0 || x == 1) return;
    if (x==2 || x==3 || x==5 || x== 7) {
        cnt[x]++;
    } else if (x == 4) {
        cnt[2] += 2, cnt[3]++;
    } else if (x == 6) {
        cnt[5]++, cnt[3]++;
    } else if (x == 8) {
        cnt[7]++, cnt[2] += 3;
    } else {
        cnt[7]++, cnt[2]++, cnt[3] += 2;
    }
}
int main() {
    int n;
    scanf("%d%s", &n, s);
    for (int i = 0; i < n; i++) {
        add(s[i] - '0');
    }
    for (int i = 9; ~i; i--) {
        while (cnt[i]--) putchar(i + '0');
    }
    puts("");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值