-
幂的阶乘【分解质因数】
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
const int inf = 0x3f3f3f3f;
int main() {
int t, n, m, cas = 1;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &m, &n);
int i = 2;
int ans = inf;
while (m != 1) {
int p = 0;
while (m % i == 0) {
m /= i;
p++;
}
if (p) {
int num = n;
int tmp = 0;
while (num) {
tmp += num/i;
num /= i;
}
ans = min(ans, tmp/p);
}
i++;
}
printf("Case %d:\n", cas++);
if (ans)
printf("%d\n", ans);
else printf("Impossible to divide\n");
}
return 0;
}
-
排列之和【】
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
typedef unsigned long long ll;
using namespace std;
const int maxn = 20;
int num[maxn], f[maxn];
int n;
void init() {
f[0] = f[1] = 1;
for (int i = 2; i < maxn; i++)
f[i] = f[i-1] * i;
}
ll cal(int x) {
ll tmp = 1;
for (int i = 0; i < 10; i++)
if (i == x)
tmp *= f[num[i]-1];
else tmp *= f[num[i]];
return (ll)(f[n-1]) / tmp;
}
int main() {
int a;
init();
while (scanf("%d", &n) != EOF && n) {
memset(num, 0, sizeof(num));
for (int i = 0; i < n; i++) {
scanf("%d", &a);
num[a]++;
}
ll sum = 0;
for (int i = 0; i < 10; i++)
if (num[i])
sum += (ll)(i) * cal(i);
ll ans = 0;
for (int i = 0; i < n; i++)
ans = ans * 10 + sum;
printf("%lld\n", ans);
}
return 0;
}