hdu-1492 The number of divisors(約數) about Humble Numbers---因子數公式
阿新 • • 發佈:2018-05-10
AI tro -- Go hdu esp clu mat -s
題目鏈接:
http://acm.hdu.edu.cn/showproblem.php?pid=1492
題目大意:
給出一個數,因子只有2 3 5 7,求這個數的因子個數
解題思路:
直接求出指數即可
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath> 6 #include<queue> 7 #include<stack> 8 #include<map> 9#include<sstream> 10 #define Mem(a, b) memset(a, b, sizeof(a)) 11 using namespace std; 12 typedef long long ll; 13 const int INF = 1e9 + 7; 14 const int maxn = 1000000+10; 15 int a[] = {2,3,5,7}; 16 int b[10]; 17 ll n; 18 int main() 19 { 20 while(scanf("%lld", &n) != EOF && n) 21 {22 Mem(b, 0); 23 for(int i = 0; i < 4; i++) 24 { 25 if(n % a[i] == 0) 26 { 27 while(n % a[i] == 0) 28 { 29 b[i]++; 30 n /= a[i]; 31 } 32 } 33 } 34 ll ans = 1; 35 for(int i = 0; i < 4; i++) 36 { 37 ans *= (b[i] + 1); 38 } 39 printf("%lld\n", ans); 40 } 41 return 0; 42 }
hdu-1492 The number of divisors(約數) about Humble Numbers---因子數公式