poj 3421 X-factor Chains(数因子分解)
来源:互联网 发布:java流程图是什么形状 编辑:程序博客网 时间:2024/05/12 05:23
题目链接
X-factor Chains
分析
对于整数
要使这个偏序链最长,显然让
换一种思考方式,将多重集合
AC code
#include <cstdio>#include <iostream>#include <vector>#include <queue>#include <algorithm>#include <cmath>#include <cstring>#include <map>#define fi first#define se secondusing namespace std;const int maxn = (1<<20)+10;const int MOD = 1e9+7;typedef long long LL;int prime[maxn];int p_size =0;void init_prime(){ memset(prime,0,sizeof(prime)); p_size = 0; for(int i=2 ; i<maxn ; ++i){ if(!prime[i]){ prime[p_size++] = i; for(LL j = (LL)i*i ;j<maxn ; j+=i)prime[j] = 1; } }}void get_factor(int n,map<int,int>& factor){ factor.clear(); for(int i=0 ; prime[i]*prime[i]<=n ; i++){ if(n%prime[i] == 0){ while (n%prime[i] == 0) { n /= prime[i]; ++factor[prime[i]]; } } } if(n>1)++factor[n];}LL fact[22];void init_fact(){ fact[0] = 1; for(int i=1 ; i<=20 ; ++i){ fact[i] = fact[i-1]*i; }}int main() { init_prime(); init_fact(); int n; while (cin>>n) { map<int,int> factor; LL num = 0; LL tmp = 1; get_factor(n,factor); for(map<int,int>::iterator it = factor.begin() ; it!=factor.end() ; ++it){ tmp*=fact[it->se]; num+=it->se; } std::cout<<num<<" " << fact[num]/tmp << '\n'; } return 0;}
0 0
- poj 3421 X-factor Chains(数因子分解)
- POJ 3421X-factor Chains【分解质因子+组合数学】
- poj 3421 X-factor Chains 素数筛选 因子分解
- POJ 3421 X-factor Chains (整数分解+组合数)
- poj 3421 X-factor Chains(分解质因数+组合数学)
- POJ 3421 X-factor Chains 分解质因数 排列组合
- POJ-3421-X-factor Chains
- poj 3421 X-factor Chains
- Poj 3421-X-factor Chains
- POJ 3421 X-factor-Chains
- poj 3421 X-factor Chains
- POJ3421 X-factor Chains【分解质因子+组合数学】
- poj 3421 --X-factor Chains(数学、组合)
- POJ 3421 X-factor Chains 排列组合
- POJ 3421 - X-factor Chains(数学)
- X-factor Chains (poj 3421 数学排列组合)
- POJ 3421 X-factor Chains (约数枚举)
- POJ 3421 X-factor Chains(数论)(筛法)()
- 洛谷 P1373 小a和uim之大逃离
- hibernate映射文件详解
- Android自定义ViewGroup的总结
- android ndk开发之一 编译ffmpeg
- spring mvc 源码研读(一)
- poj 3421 X-factor Chains(数因子分解)
- iOS - Runtime 之 Method Swizzling(方法交换)
- 欢迎使用CSDN-markdown编辑器
- 【BZOJ 3142】[Hnoi2013]数列 数学+差分
- request方法详解
- vim无法"+y复制的问题
- Android开发:MVP模式的学习
- 模板数组类_作业讲解和思想强化(数据类型和算法的分离)
- 给一个二叉树,每个节点都是正或负整数,如何找到一个子树,它所有节点的和最大?