Intelligent Factorial Factorization LightOJ
来源:互联网 发布:zip解压软件下载mac版 编辑:程序博客网 时间:2024/05/21 21:37
题目
Intelligent Factorial Factorization
LightOJ - 1035Given an integer N, you have to prime factorize N! (factorial N).
Input starts with an integer T (≤ 125), denoting the number of test cases.
Each case contains an integer N (2 ≤ N ≤ 100).
For each case, print the case number and the factorization of the factorial in the following format as given in samples.
Case x: N = p1 (power of p1) * p2 (power of p2) * ...
Here x is the case number, p1, p2 ... are primes in ascending order.
3
2
3
6
Case 1: 2 = 2 (1)
Case 2: 3 = 2 (1) * 3 (1)
Case 3: 6 = 2 (4) * 3 (2) * 5 (1)
思路
素数分解。。。
代码
#include <iostream>#include <cstdio>#include <algorithm>#include <string>#include <cstring>#include <set>#include <map>#include <vector>#define MAX_N 0x3F3F3F3Fusing namespace std;typedef long long ll;map<int, int> pfactMap;void primeFact(int n);int main(){int T, N;cin >> T;for (int i = 1; i <= T; i++) {cin >> N;pfactMap.clear();for (int n = N; n > 1; n--) {primeFact(n);}cout << "Case " << i << ": ";cout << N << " = ";map<int, int>::iterator it;int s;for (it = pfactMap.begin(), s = 0; it != pfactMap.end(); it++, s++) {cout << (it)->first << " (" << (it)->second << ")";if (s != pfactMap.size()-1) cout << " * ";}cout << endl;} return 0;}void primeFact(int n) {for (int i = 2; i*i <= n; i++) {if (n % i == 0) {//pfactMap.insert(n%i);pfactMap[i]++;primeFact(n/i);return;}}//pfactMap.insert(n);pfactMap[n]++;return;}
0 0
- Intelligent Factorial Factorization LightOJ
- LightOJ 1035 Intelligent Factorial Factorization
- LightOJ 1035 Intelligent Factorial Factorization
- LightOJ 1035 Intelligent Factorial Factorization
- lightoj 1035 Intelligent Factorial Factorization 因式分解
- LightOJ 1035 Intelligent Factorial Factorization 全排列
- LightOJ 1035 - Intelligent Factorial Factorization (求因子)
- LightOJ 1035 Intelligent Factorial Factorization 因子分解水题
- LightOJ 1035 Intelligent Factorial Factorization [预处理+一半的 质因子分解]【数论】
- Light OJ 1035 - Intelligent Factorial Factorization
- Light OJ 1035 Intelligent Factorial Factorization
- LightOJ1035 Intelligent Factorial Factorization(算数基本定理)
- LightOJ 1045 Digits of Factorial
- LightOJ 1045 Digits of Factorial
- LightOJ 1045 Digits of Factorial
- LightOJ - 1045 Digits of Factorial
- lightoj 1045 - Digits of Factorial
- 【LightOJ 1045 Digits of Factorial】
- 喵喵喵
- VS2012创建C++项目失败,解决方法
- Java中的String,StringBuffer,StringBuilder区别
- 努力到感动自己,拼搏到无能为力
- Python入门笔记
- Intelligent Factorial Factorization LightOJ
- 剑指offer-4.重建二叉树
- 爬虫-分析Ajax
- HTTP之缓存
- 保存退出vim编辑
- 数组的基本操作
- 详解TCP状态转移图
- 类型萃取
- 【软考】设计模式-模板方法