POJ 3993 Not So Flat After All (快速求质因子)
来源:互联网 发布:c语言分布式服务框架 编辑:程序博客网 时间:2024/05/28 17:04
先贴上快速求质因子模板
#include <iostream>#include <vector>using namespace std;void get(int n, vector<int>&a){a.clear();// i小于等于sqrt(n)的原因:// 对于任意的n来说,它的质因子比sqrt(n)大的最多只有一个for (int i = 2; i*i < n; i++){while (n%i == 0){a.push_back(i);n /= i;}}// 把比sqrt(n)大的因子添加进去if (n>1)a.push_back(n);}
这道题题意很简单,直接贴代码
#include <iostream>#include <set>using namespace std;set<int>sum;void get(int x){for (int i = 2; i*i <= x; i++){while (x%i == 0){sum.insert(i);x /= i;}}if (x > 1){sum.insert(x);}}int main(){int n, m, kase = 1;while (cin >> n >> m&&n&&m){sum.clear();get(n);get(m);int ans = 0;set<int>::iterator it = sum.begin();for (; it != sum.end(); it++){int a = 0, b = 0;int temp = *it;while (n%temp == 0)a++, n /= temp;while (m%temp == 0)b++, m /= temp;ans += (a > b ? a - b : b - a);}cout << kase++ << ". " << sum.size() << ":" << ans << endl;}}
0 0
- POJ 3993 Not So Flat After All (快速求质因子)
- POJ 3993 Not So Flat After All
- POJ 3993 Not So Flat After All
- POJ 3993 Not So Flat After All(质因数)
- POJ 3993 Not So Flat After All(质因数)
- poj3993Not So Flat After All(筛法素数+分解质因子)
- HDU 3353 Not So Flat After All(数论)
- 西南交大公开赛 Not So Flat After All(合数分解)
- POJ 2992 Divisors (快速求阶乘的素因子)
- POJ 2992-Divisors(求组合数质因子的个数)
- poj 3421--求整数的质因子及其数量
- POJ 1811 Prime Test 【快速判质+因子分解】【模板】
- 求最大质因子
- 求质因子
- 快速分解质因子
- poj 2992 Divisors(求因子个数)
- poj 4016 Flat 水题
- 求质因子的模板
- BFS算法实现(Qt界面版)
- 电路的时间常数
- BootStrap3.0学习--起步
- 无偏估计与自由度
- BootStrap3.0学习--全局 CSS 样式
- POJ 3993 Not So Flat After All (快速求质因子)
- BootStrap3.0学习--组件
- BootStrap3.0学习--JavaScript 插件
- maven 仓库地址收藏
- [LeetCode]*106.Construct Binary Tree from Inorder and Postorder Traversal
- JavaScript浏览器对象之History对象 Navigator对象 Location对象 Screen对象
- BruteForceMatcher和FlannBasedMatcher函数
- 利用大数据帮助医疗机构的5种方法
- LeetCode_Regular Expression Matching