POJ2917的加强版,把n变成了n!
n!的每个质因子数量就是1~n的对应质因子个数累加
这是模拟赛的,有取模的,P1445 [Violet]樱花
int prime[N], v[N];
int cnt, c[N];
inline void Euler_Sieve(int mx) {
rep(i, 2, mx) {
if(!v[i]) {
v[i] = i;
prime[++cnt] = i;
}
rep(j, 1, cnt) {
if(prime[j] > v[i] || 1ll * prime[j]*i > mx) break;
v[prime[j]*i] = prime[j];
}
}
}
int main() {
Euler_Sieve(T);
rep(i, 1, cnt) {
int temp(T);
while(1){
if(temp==0||prime[i]>T) break;
c[prime[i]]+=temp/prime[i];
temp/=prime[i];
}
}
lxl ans(1);
rep(i, 1, T) {
if(c[i]) {
ans = (ans * (2 * c[i] + 1) ) % mod;
}
}
out(ans, '
');
return 0;
}
这个是spoj的,要开高精度
const int N = 1000007;
const int len = 2607, W = 1e9;
struct Big {
lxl x[len];
int sz;
void Trim() {
while(sz > 1 && !x[sz - 1])--sz;
}
Big(lxl a = 0) {
memset(x, 0, sizeof(x)), sz = 0;
do x[sz++] = a % W;
while(a /= W);
}
} ans;
void Write(const Big & a) {
printf("%lld", a.x[a.sz - 1]);
drp(i, a.sz - 2, 0)printf("%09lld", a.x[i]);
}
Big operator*(const Big & a, const Big & b) {
Big c;
c.sz = a.sz + b.sz;
rep(i, 0, a.sz - 1)rep(j, 0, b.sz - 1) {
c.x[i + j] += a.x[i] * b.x[j];
c.x[i + j + 1] += c.x[i + j] / W, c.x[i + j] %= W;
}
c.Trim();
return c;
}
namespace solve {
int prime[N], v[N];
int cnt, c[N];
inline void Euler_Sieve(int mx) {
rep(i, 2, mx) {
if(!v[i]) {
v[i] = i;
prime[++cnt] = i;
}
rep(j, 1, cnt) {
if(prime[j] > v[i] || 1ll * prime[j]*i > mx) break;
v[prime[j]*i] = prime[j];
}
}
}
int main() {
T = 1e5;
Euler_Sieve(T);
while(1) {
cin >> T;
if(!T) break;
memset(c,0,sizeof c);
rep(i, 1, cnt) {
int temp(T);
while(1) {
if(temp == 0 || prime[i] > T) break;
c[prime[i]] += temp / prime[i];
temp /= prime[i];
}
}
ans = 1;
rep(i, 1, T) {
if(c[i]) {
ans = ans * (2 * c[i] + 1) ;
}
}
Write(ans);
cout << '
';
}
return 0;
}
}
main() {
solve::main();
return 0;
}