/*==================================================*| 分解质因数,可能有些地方需要改为long long \*==================================================*/ const int MAXN=100010; int prm[MAXN+1]; bool is[MAXN+1]; int getprm(int n){ int i, j, k = 0; int s, e = (int)(sqrt(0.0 + n) + 1); memset(is, 1, sizeof(is)); prm[k++] = 2; is[0] = is[1] = 0; for(i = 4; i < n; i += 2) is[i] = 0; for(i = 3; i < e; i += 2) if(is[i]) { prm[k++] = i; for(s = i * 2, j = i * i; j < n; j += s) is[j] = 0; // 因为j是奇数,所以+奇数i后是偶数,不必处理! } for( ; i < n; i += 2) if(is[i]) prm[k++] = i; return k; // 返回素数的个数 } ll factor[101][2]; int facnt; int div(ll x) { int num=1; facnt=0; ll tmp=x; for(int i=0;prm[i]<=tmp/prm[i];i++) { if(tmp%prm[i] == 0) { factor[facnt][0]=prm[i]; factor[facnt][1]=0; while(tmp%prm[i] == 0) { tmp/=prm[i]; factor[facnt][1]++; } num*=(factor[facnt][1]+1); facnt++; } } if(tmp!=1) { factor[facnt][0]=tmp; factor[facnt++][1]=1; num*=2; } return num; }
时间: 2024-10-08 13:26:25