题目地址:
http://acm.hdu.edu.cn/showproblem.php?pid=2421
大意:
给你2个数A,B,范围为1到100万。N是A的B次方。设a1,a2,……ai为N的因子,设k1,k2……,ki为a1,a2,……ai的因子个数。求k1,k2……,ki的立方和。
思路:
算数基本定理推论:
任一个大于1的整数a都能够唯一的写成
a=p1^a1*p2^a2……pk^ak>0.
其中p1<p2<……<pk.且pk为素数。
代码如下:
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<algorithm> using namespace std; #define MAXN 1010 bool is_prime[MAXN]; int prime[170]; void pre() //素数打表 { int i, j, k = 0; memset(is_prime, 1, sizeof(is_prime)); for(i = 2; i < 35; ++i) { if(is_prime[i]) for(j = i; j * i < MAXN; ++j) is_prime[i * j] = 0; } for(i = 2; i < MAXN; ++i) if(is_prime[i]) prime[k++] = i; } int main() { int m, n, i,t = 1,count; int sum; pre(); while(scanf("%d%d", &m, &n) != EOF) { sum = 1; for(i = 0; i < 169; ++i) //算数基本定理推论 { count = 0; while(m % prime[i] == 0 && m != 1) { m /= prime[i]; count++; } count =( count * n + 1) % 10007; count=count * (count + 1) / 2 % 10007; sum = sum * (count * count % 10007) % 10007; if(m == 1) break; } if(m != 1) { count=(n + 1) % 10007; count=count * (count + 1) / 2 % 10007; sum = sum * (count * count % 10007) % 10007; } printf("Case %d: %d\n", t++, sum); } return 0; }