LightOJ 1341 Aladdin and the Flying Carpet【整数分解】
2016-04-17 10:30
489 查看
题目链接:
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; }
相关文章推荐
- Kali 强大的抓包工具 WIRESHARK
- LightOJ 1341 Aladdin and the Flying Carpet【整数分解】
- LightOJ 1341 Aladdin and the Flying Carpet【整数分解】
- 视频封装格式之mkv--1
- java native关键字
- 20145236 《Java程序设计》实验二实验报告
- 进程间的通信方式与进程间同步方式
- php session和cookie
- IE请求和响应报文解释
- BestCoder Round #80(B)高精度
- 一些linux的基本操作
- Oracle 11g standby主从配置
- Oracle笔记(三) Scott用户的表结构
- 水仙花数的输出
- 武器游戏
- 多文件游戏
- Android开发之开发者头条(一)启动页实现
- 一个字符串反转的小例子
- Oracle笔记(二) SQLPlus命令
- http2.0 相对于 http1.1的优势