UVa 294 - Divisors
2015-03-18 12:21
387 查看
通过这道题学到了2个知识:
1.一个数的质因子一定小于等于这个数的开根
2.一个数的因子(约数)数等于 π(各质因子数+1)
1.一个数的质因子一定小于等于这个数的开根
2.一个数的因子(约数)数等于 π(各质因子数+1)
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int maxn = 55555; //#define DEBUG int vis[maxn]; int prime[maxn]; int cnt = 0; void GetPrime(){ memset(vis,0,sizeof(vis)); int m = sqrt(maxn) + 1; for(int i = 2; i < m; i++)if(!vis[i]){ for(int j = i * i; j < maxn; j += i) vis[j] = 1; } for(int i = 2; i < maxn; i++) if(!vis[i]) prime[cnt++] = i; #ifdef DEBUG for(int i = 0; i < cnt; i++) printf("%d ",prime[i]); #endif // DEBUG } int solve(int n){ int sum = 1; for(int i = 0; i < cnt && n > 1; i++){ if(n % prime[i] == 0){ int c = 1; while(n % prime[i] == 0){ c ++; n /= prime[i]; } sum *= c; } } return sum; } int main(){ int n,T; GetPrime(); scanf("%d",&T); while(T--){ int a,b; scanf("%d%d",&a,&b); int temp = 0; int ret; for(int i = a; i <= b; i++){ int e = solve(i); if(temp < e){ temp = e; ret = i; } } printf("Between %d and %d, %d has a maximum of %d divisors.\n",a,b,ret,temp); } return 0; }
相关文章推荐
- uva 294 divisors
- uva 294 Divisors 求因子个数
- Divisors UVA - 294
- UVa294 Divisors
- UVa 294 Divisors
- UVA294 - Divisors
- UVA294 UVALive5595 Divisors【正因子数】
- UVA 294 294 - Divisors (数论)
- UVA 294 Divisors
- Uva 294 Divisors(唯一分解定理)
- UVa 294-Divisors
- UVa 294 (因数的个数) Divisors
- UVA 294(p344)----Divisors
- uva 294 ——Divisors
- UVA 294 Divisors( 因子分解)
- UVA 294 294 - Divisors (数论)
- UVa294 - Divisors
- UVa 294 Divisors
- UVA 294 Divisors(唯一分解定理 + 除数函数)
- UVa 294 - Divisors