n<=10^6
m<=10^6
p=2^32
用unsigned int 可以避免取模
我写的SB超时 阶乘分解代码
#include利用阶乘的质因数分解!#include #include #include #include #include #include #include #include #define oo 0x13131313using namespace std;const unsigned int N=1000000+5;unsigned int tag[N],p[N],z[N],mm[N];unsigned int cnt = 0;unsigned int n,m;unsigned int quickpow(unsigned int m,unsigned int n){ unsigned int b = 1; while (n > 0) { if (n & 1) b = (b*m); n = n >> 1 ; m = (m*m); } return b;}void get_prime(){ tag[1]=1; tag[0]=1; for (unsigned int i = 2; i < N; i++) { if (!tag[i]) p[cnt++] = i; for (unsigned int j = 0; j < cnt && p[j] * i < N; j++) { tag[i*p[j]] = 1; if (i % p[j] == 0) break; } }}unsigned int FIND(unsigned int x){ unsigned int l=0,r=cnt-1; while(l<=r) { unsigned int m=(l+r)/2; if(p[m]==x) return m; else if(p[m] >T; while(T--) { cin>>n>>m; memset(z,0,sizeof(z)); memset(mm,0,sizeof(mm)); for(unsigned int i=n;i>=n-m+1;i--) fenjie(z,i); for(unsigned int i=1;i<=m;i++) fenjie(mm,i); unsigned int ans=1; for(unsigned int i=0;i
比如250!
1*2*3*4*5*6*7*8*9*10*11*12*13*14.....250
中3的质因子个数 除了3后变成(不是倍数的不管)计算3^1次方的为250/3个
又变成 1 2 3 .....250除3
重复上面 知道 3^2 为250/(3^2)
所以阶乘的质因数分解是另外的简单算法
void getcn(int n){ int ans = 0; int i; for (i = 1; i <= prime[0] && prime[i] <= n; i++) { int tmp = n; while (tmp) { num[i] += tmp / prime[i]; tmp /= prime[i]; } } num[0] = i;}所以最后的代码是
#include#include #include #include #include #include #include #include #include #include #include #include #include