码迷,mamicode.com
首页 > 其他好文 > 详细

poj3421

时间:2018-11-30 00:40:31      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:sync   转化   cti   amp   can   factorial   oid   time   main   

对x分解素因子,然后对素因子进行全排列,每一种排列都是最长序列并且满足条件

然后问题转化为n元素可重集的全排列个数

设有k种元素,每种元素有ai个

那么答案就是n!/a1!*a2!*a3!..ak!

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<assert.h>
#include<ctime>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<sstream>
#include<stack>
#include<queue>
#include<string>
#include<bitset>
#include<algorithm>
using namespace std;
#define me(s)  memset(s,0,sizeof(s))
#define pf printf
#define sf scanf
#define Di(x) int x;scanf("%d",&x)
#define in(x) inp(x)
#define in2(x,y) inp(x),inp(y)
#define in3(x,y,z) inp(x),inp(y),inp(z)
#define ins(x) scanf("%s",x)
#define ind(x) scanf("%lf",&x)
#define IO ios_base::sync_with_stdio(0);cin.tie(0)
#define READ freopen("C:/Users/ASUS/Desktop/in.txt","r",stdin)
#define WRITE freopen("C:/Users/ASUS/Desktop/out.txt","w",stdout)
template<class T> void inp(T &x) {//读入优化
    char c = getchar(); x = 0;
    for (; (c < 48 || c>57); c = getchar());
    for (; c > 47 && c < 58; c = getchar()) { x = (x << 1) + (x << 3) + c - 48; }
}
typedef pair <int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-15;
const int maxn=21;
ull factorial[maxn+1];
void Solve(int x){
    ull sum=0,ret=1;
    for(int i=2;i*i<=x;i++){
        int cnt=0;
        while(x%i==0){
            x/=i;
            cnt++;
        }
        ret*=factorial[cnt];
        sum+=cnt;
    }
    sum+=x>1?1:0;
    cout<<sum<< <<factorial[sum]/ret<<endl;
}
int main(){
    factorial[0]=factorial[1]=1;
    for(int i=2;i<=maxn;i++)
    factorial[i]=factorial[i-1]*i;
    int n;
    while(sf("%d",&n)==1){
        Solve(n);
    }

}

 

poj3421

标签:sync   转化   cti   amp   can   factorial   oid   time   main   

原文地址:https://www.cnblogs.com/033000-/p/10041628.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!