CF : B. Easy Number Challenge 数论(素数)
http://codeforces.com/contest/236/problem/B
题意:
给定a,b,c三个数,d(i)表示i的因子的个数,求
思路:
任何一个数a都可以分解为素因子的乘积 a = p1^n1*p2^n2*p3^n3......然后他的因子的个数就为ans = (n1 + 1) * (n2 + 1)*(n3 + 1)....
时间复杂度为O(n^3*x)这个x是多少真不知道怎么想,。
还有一种方法是直接枚举1-100作为因子所能组成的数,每次组成该数就+1。最后直接的结果求和即可。
View Code
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <set> #include <map> #include <string> #define CL(a,num) memset((a),(num),sizeof(a)) #define iabs(x) ((x) > 0 ? (x) : -(x)) #define Min(a,b) (a) > (b)? (b):(a) #define Max(a,b) (a) > (b)? (a):(b) #define ll long long #define inf 0x7f7f7f7f #define MOD 1073741824 #define lc l,m,rt<<1 #define rc m + 1,r,rt<<1|1 #define pi acos(-1.0) #define test puts("<------------------->") #define maxn 100007 #define M 100007 #define N 100007 using namespace std; int prim[N],f[N]; void init() { int i,j; CL(f,0); f[2] = 0; for (i = 2; i*i < N; ++i) { if (!f[i]) { for (j = 2*i; j < N; j += i) { f[j] = 1; } } } int len = 0; for (i = 2; i < N; ++i) { if (!f[i]) prim[len++] = i; } } ll cal(int n) { int i; ll ans = 1; for (i = 0; prim[i]*prim[i] <= n; ++i) { if (n%prim[i] == 0) { int ct = 0; while (n%prim[i] == 0) { ct++; n = n/prim[i]; } ans = (ans%MOD * (ct + 1)%MOD)%MOD; } } if (n != 1) { ans *= 2; ans = ans%MOD; } return ans; } int main() { //freopen("data.in","r",stdin); int i,j,k; int a,b,c; init(); while (~scanf("%d%d%d",&a,&b,&c)) { ll ans = 0; for (i = 1; i <= a; ++i) { for (j = 1; j <= b; ++j) { for (k = 1; k <= c; ++k) { ans += cal(i*j*k); ans %= MOD; } } } cout<<ans<<endl; } return 0; }
View Code
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <set> #include <map> #include <string> #define CL(a,num) memset((a),(num),sizeof(a)) #define iabs(x) ((x) > 0 ? (x) : -(x)) #define Min(a,b) (a) > (b)? (b):(a) #define Max(a,b) (a) > (b)? (a):(b) #define ll long long #define inf 0x7f7f7f7f #define MOD 1073741824 #define lc l,m,rt<<1 #define rc m + 1,r,rt<<1|1 #define pi acos(-1.0) #define test puts("<------------------->") #define maxn 100007 #define M 1000007 #define N 107 using namespace std; int num[M]; int main() { //freopen("data.in","r",stdin); int i,j,k; int a,b,c; while (~scanf("%d%d%d",&a,&b,&c)) { CL(num,0); for (i = 1; i < M; ++i) { for (j = i; j < M; j += i) num[j]++; } ll ans = 0; for (i = 1; i <= a; ++i) { for (j = 1; j <= b; ++j) { for (k = 1; k <= c; ++k) { ans += num[i*j*k]; ans %= MOD; } } } cout<<ans<<endl; } return 0; }