标签:get pow include stdio.h targe href main blog size
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1492
这里先讲一下约数个数定理:
对于正整数x,将其质因分解为 x = pow(p1, a) * pow*(p2, b) * pow(p3, c) * ...
则其约数个数为:num(x) = (a+1) * (b+1) * (c+1) *...
推导:
那么这道题直接代这个公式好啦~
题意:
给出一个64bit的数,求它的约数的个数;
代码:
1 #include <iostream>
2 #include <stdio.h>
3 #define ll long long
4 using namespace std;
5
6 int main(void){
7 ll n;
8 while(scanf("%lld", &n)&&n){
9 int a[4]={1, 1, 1, 1};
10 int b[4]={2, 3, 5, 7};
11 for(int i=0; i<4; i++){
12 while(n%b[i]==0){
13 a[i]++;
14 n/=b[i];
15 }
16 }
17 printf("%d\n", a[0]*a[1]*a[2]*a[3]);
18 }
19 return 0;
20 }
标签:get pow include stdio.h targe href main blog size
原文地址:http://www.cnblogs.com/geloutingyu/p/5994786.html