BZOJ1300 [LLH邀请赛]大数计算器

一开始以为暴力搞,后来看了数据范围还以为要FFT,各种被虐,然后Orz Seter大神!!!

我只想到了前三位:a * b <=> 10^(log(a) + log(b)),于是把乘的数都先log了最后再变回去就可以了。。。

然后后九位的方法:

Seter:"对于素数a,在N!中出现了N / a + N / a ^ 2+...次"

于是C(M, N) = N! / M! / (N - M)!就可以求每个质因数出现的次数,搞定!

 /**************************************************************
Problem: 1300
User: rausen
Language: C++
Result: Accepted
Time:164 ms
Memory:1792 kb
****************************************************************/ #include <cstdio>
#include <cmath>
#include <algorithm> using namespace std;
typedef long long LL; int n, m;
LL ans = ;
bool p[]; int main(){
scanf("%d%d", &n, &m);
m = min(m, n - m); int i, j, x, y, c, s;
double k = , f = ;
for (i = ; i <= n; ++i)
if (!p[i]){
for (j = n, x = n - m, y = m; j;){
c = (j /= i) - (x /= i) - (y /= i), s = i;
for (c <<= ; c >>= ; s *= s)
if (c & ) ans *= s, ans %= (LL) 1e12;
}
if (i <= )
for (j = i * i; j <= n; j += i)
p[j] = ;
}
for (i = ; i <= m; ++i){
if (f > 1e7)
k += log10(f), f = ;
f = f * (n - m + i) / i;
}
k += log10(f); if (k < ) printf("%lld\n", ans);
else printf("%d...%09lld\n", (int) (pow(, k - floor(k) + ) + 1e-), ans % (int) 1e9);
return ;
}

p.s.话说Seter竟然可以C、C++混用,真是碉堡了。。。

上一篇:windows系统调用 进程终止


下一篇:mac 终端下ssh 登录远程服务器不发输入中文