LightOJ 1341 Aladdin and the Flying Carpet【整数分解】
2016-04-17 10:30
281 查看
原文链接:https://www.geek-share.com/detail/2671860205.html
题目链接:
http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1341
题意:
给定一个数,将其拆分成两个数的乘积,问有多少种组合,其中两个因子均大于等于给定值。
分析:
整数分解,找质因子的个数,组合一下就好。
注意题目中说不要正方形,然后最后处理一下每种组合被算两次的情况。
代码:
#include <iostream> #include <vector> using namespace std; const int maxn = 1e6 + 5; int flag[maxn], prime[maxn]; typedef long long ll; int tot = 0; void getprime() { fill(flag, flag + maxn, 1); for(int i = 2; i < maxn; i++){ if(flag[i]){ prime[tot++] = i; for(int j = 2 * i; j < maxn; j += i){ flag[j] = 0; } } } } int main (void) { int n; int T;cin>>T; getprime(); ll a, b, t; int cas = 1; ll cnt; while(T--){ cin>>a>>b; t = a; ll ans = 1; if(a / b < b) { cout<<"Case "<<cas<<": "<<0<<endl; cas++; continue; } for(int i = 0; i < tot && prime[i] * prime[i]<= a; i++){ cnt = 0; while(a % prime[i] == 0){a /= prime[i]; cnt++;} ans *= (cnt + 1); } if(a > 1) ans *= 2; ans /= 2; for(ll i = 1; i < b; i++){ if(t % i == 0) ans--; } cout<<"Case "<<cas<<": "<<ans<<endl; cas++; } return 0; }
转载于:https://www.cnblogs.com/Tuesdayzz/p/5758660.html
相关文章推荐
- 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
- 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(合数)唯一分解定理
- Aladdin and the Flying Carpet LightOJ - 1341 数论/唯一分解定理
- Aladdin and the Flying Carpet LightOJ - 1341 (唯一分解定理求因数个数)
- 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
- LightOJ-1341 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
- LightOJ 1341 Aladdin and the Flying Carpet(质因数分解、因子个数)
- 1341 - Aladdin and the Flying Carpet ---light oj (唯一分解定理+素数筛选)