zoukankan      html  css  js  c++  java
  • POJ3421 X-factor Chains

    嘟嘟嘟

    题目大意:给一个数x,让你求这样一个最长的序列,以及最长的序列的种数:

    1.第0项为1,最后一项为x(序列长度不算这两项)。

    2.每一项都是x的因子。

    3.对于任意的ai和ai+1,ai < ai+1且ai | ai+1

    每一项都是x的因子,那么先把x分解质因数,用这些数凑成的数一定都是x的因子。然后要满足第三条,那么ai+1一定由ai乘以一个质因数得到,所以最长长度就是质因数指数之和tot。

    再求方案:先不考虑pici中,ci = 1,那么第一个数有tot种选法,第二个数有tot - 1种……所以总方案数是tot!。再考虑重复的数,就再除以 ci!。

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<cstdlib>
     7 #include<cctype>
     8 #include<vector>
     9 #include<stack>
    10 #include<queue>
    11 using namespace std;
    12 #define enter puts("") 
    13 #define space putchar(' ')
    14 #define Mem(a, x) memset(a, x, sizeof(a))
    15 #define rg register
    16 typedef long long ll;
    17 typedef double db;
    18 const int INF = 0x3f3f3f3f;
    19 const db eps = 1e-8;
    20 //const int maxn = ;
    21 inline ll read()
    22 {
    23     ll ans = 0;
    24     char ch = getchar(), last = ' ';
    25     while(!isdigit(ch)) {last = ch; ch = getchar();}
    26     while(isdigit(ch)) {ans = ans * 10 + ch - '0'; ch = getchar();}
    27     if(last == '-') ans = -ans;
    28     return ans;
    29 }
    30 inline void write(ll x)
    31 {
    32     if(x < 0) x = -x, putchar('-');
    33     if(x >= 10) write(x / 10);
    34     putchar(x % 10 + '0');
    35 }
    36 
    37 int n;
    38 ll fac[21];
    39 void init()
    40 {
    41   fac[1] = 1;
    42   for(int i = 2; i < 21; ++i) fac[i] = fac[i - 1] * i;
    43 }
    44 
    45 void solve(int n)
    46 {
    47   int tot = 0;
    48   ll und = 1;
    49   for(int i = 2; i * i <= n; ++i)
    50     {
    51       if(!(n % i))
    52     {
    53       int cnt = 0;
    54       for(; !(n % i); n /= i, cnt++);
    55       tot += cnt;
    56       und *= fac[cnt];
    57     }
    58     }
    59   if(n > 1) tot++;
    60   write(tot); space; write(fac[tot] / und); enter;
    61 }
    62 
    63 int main()
    64 {
    65   init();
    66   while(scanf("%d", &n) != EOF) solve(n);
    67   return 0;
    68 }
    View Code
  • 相关阅读:
    软件体系架构复习要点
    Operating System on Raspberry Pi 3b
    2019-2020 ICPC North-Western Russia Regional Contest
    2019 ICPC ShenYang Regional Online Contest
    2019 ICPC XuZhou Regional Online Contest
    2019 ICPC NanChang Regional Online Contest
    2019 ICPC NanJing Regional Online Contest
    Codeforces Edu Round 72 (Rated for Div. 2)
    Codeforces Round #583 (Div.1+Div.2)
    AtCoder Beginning Contest 139
  • 原文地址:https://www.cnblogs.com/mrclr/p/9774496.html
Copyright © 2011-2022 走看看