LightOj1341_Aladdin and the Flying Carpet_算数基本定理
2017-07-20 21:09
453 查看
题意
有一个矩形,它不是正方形,并且它得较短边不能小于 k ,给出它得面积 n,求满足要求的矩形的数目。思路
公式可以在这里找到http://blog.csdn.net/yuege38/article/details/65486799
题目的答案就是 (n 的因数的数目 / 2)。
需要注意的一点,一般的分解素因数会超时,需要提前打个素数表。
题目链接
Vjudge链接https://vjudge.net/contest/169048#problem/C
AC代码
#include<cstdio> #include<iostream> using namespace std; typedef long long LL; const int maxn = 1e6 + 10; LL Cas, n, k; LL prime[maxn], len; void get_prime() { len = 0; for(LL i= 2; i<= maxn - 10; i++) { if(prime[i] == 0) prime[len ++] = i; for(int j= 0; j< len && i * prime[j] <= maxn - 10; j++) { prime[i * prime[j]] = 1; if(i % prime[j] == 0) break; } } } LL get_factor() { if(n / k < k) return 0; LL res = 1, left = n; for(int i = 0; i< len && prime[i] * prime[i]<= left;i++) { int c = 0; while(left % prime[i] == 0) { c ++; left /= prime[i]; } res *= (c + 1); } if(left > 1) res <<= 1; res >>= 1; for(int i= 1; i< k; i++) if(n % i == 0) res--; return res; } int main() { get_prime(); scanf("%d", &Cas); for(int cas= 1; cas <= Cas; cas ++) { scanf("%lld %lld", &n, &k); printf("Case %d: %lld\n", cas, get_factor()); } return 0; }
相关文章推荐
- 【算数基本定理(唯一分解定理)】Aladdin and the Flying Carpet LightOJ - 1341
- LightOJ 1341 - Aladdin and the Flying Carpet(算术基本定理啊)
- 【基本算术定理 && 质因数分解】LightOJ - 1341 Aladdin and the Flying Carpet
- Light OJ 1341 Aladdin and the Flying Carpet(算数基本定理)
- LightOJ 1341 Aladdin and the Flying Carpet(算术基本定理)
- lightoj 1341 - Aladdin and the Flying Carpet / lightoj 1236 - Pairs Forming LCM(算术基本定理)
- LightOJ 1341 Aladdin and the Flying Carpet(算术基本定理)
- LightOJ - 1341 Aladdin and the Flying Carpet(唯一分解定理)
- Aladdin and the Flying Carpet LightOJ - 1341(合数)唯一分解定理
- LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)
- Aladdin and the Flying Carpet LightOJ - 1341 数论/唯一分解定理
- Lightoj1341——Aladdin and the Flying Carpet(算术基本定理)
- LightOJ 1341 Aladdin and the Flying Carpet(唯一分解定理)
- LightOJ 1341 Aladdin and the Flying Carpet
- LightOJ - 1341- Aladdin and the Flying Carpet
- Aladdin and the Flying Carpet (算术基本定理)
- LightOJ 1341 Aladdin and the Flying Carpet【整数分解】
- lightOJ 1341 Aladdin and the Flying Carpet
- LightOJ 1356 Aladdin and the Flying Carpet(唯一分解定理)
- LightOJ 1341 Aladdin and the Flying Carpet【整数分解】