X-factor Chains
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6212   Accepted: 1928

Description

Given a positive integer X, an X-factor chain of length m is a sequence of integers,

1 = X0X1X2, …, Xm = X

satisfying

Xi < Xi+1 and Xi | Xi+1 where a | b means a perfectly divides into b.

Now we are interested in the maximum length of X-factor chains and the number of chains of such length.

Input

The input consists of several test cases. Each contains a positive integer X (X ≤ 220).

Output

For each test case, output the maximum length and the number of such X-factors chains.

Sample Input

2
3
4
10
100

Sample Output

1 1
1 1
2 1
2 2
4 6
100=2*2*5*5;
所以最长为4,然后对2,2,5,5排列组合,但一直RE,TLE
 #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
#define LL long long
#define Max ((1<<20)+2)
bool a[Max];
int prime[Max];
int num[Max];
LL init[];
void get_prime() //埃氏筛法选取素数
{
int i,j,p=;
memset(a,,sizeof(a));
a[]=a[]=;
for(i=;i<=Max;i++)
{
if(a[i]==)
{
prime[p++]=i;
for(j=i*;j<Max;j+=i)
a[j]=;
}
}
init[]=;
for(i=;i<=;i++)
init[i]=i*init[i-];
return;
}
int main()
{
int ans,n,i,j,k,u;
get_prime();
LL p,t;
freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF)
{
ans=,k=,t=;
i=;
while(n>)
{
if(n%prime[i]==)
{
u=;
while(n%prime[i]==)
{
n=n/prime[i];
u++;
}
t*=init[u];
ans+=u;
k++;
}
if(a[n]==)
{
ans++;
break;
}
i++;
}
p=init[ans];
LL s=p/t;
printf("%d %I64d\n",ans,s);
}
return ;
}

X-factor Chains(POJ3421 素数)的更多相关文章

  1. X-factor Chains [POJ3421] [素数]

    Description    给定一个正整数X, 一个长度为m的X-因子链是由m+1个整数组成的.其中    1 = X0, X1, X2, …, Xm = X 满足Xi < Xi+1 且 Xi ...

  2. 杭电 2136 Largest prime factor(最大素数因子的位置)

    Largest prime factor Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  3. UVA 11610 Reverse Prime (数论+树状数组+二分,难题)

    参考链接http://blog.csdn.net/acm_cxlove/article/details/8264290http://blog.csdn.net/w00w12l/article/deta ...

  4. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  5. poj3421 X-factor Chains(重复元素的全排列)

    poj3421 X-factor Chains 题意:给定正整数$x(x<=2^{20})$,求$x$的因子组成的满足任意前一项都能整除后一项的序列的最大长度,以及满足最大长度的子序列的个数. ...

  6. HDOJ/HDU 2710 Max Factor(素数快速筛选~)

    Problem Description To improve the organization of his farm, Farmer John labels each of his N (1 < ...

  7. HDOJ(HDU) 2136 Largest prime factor(素数筛选)

    Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...

  8. POj3421 X-factor Chains(质因数分解+排列组合)

    POj3421X-factor Chains 一开始没读懂题意,不太明白 Xi | Xi+1 where a | b means a perfectly divides into b的意思,后来才发现 ...

  9. Max Factor(素数筛法)题解

    Max Factor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

随机推荐

  1. head直接复制的

    <script type="application/x-javascript"> addEventListener("load", function ...

  2. Is there a complete List of JVM exit codes

    Argument passed to System.exit(x) -> becomes the JVM exit code. Exit code 0 is used to indicate n ...

  3. delphi 打开文件夹并定位到一个文件(关键是/select参数)

    strFileName := FcxLV[nIndex].Items.Item[FcxLV[nIndex].ItemIndex].SubItems.Strings[0]; //路径  ShellExe ...

  4. MVC4+Springnet+Nhibernate学习系列随笔(一)

    Springnet与asp.net mvc4集成大体步骤 1.首先要在MVC项目中引用的两个程序集(Spring.Web与Spring.Web.Mvc4) 集 2.修改MVC项目的Global.asa ...

  5. PowerShell官方的MSDN

    https://msdn.microsoft.com/en-us/powershell/mt173057.aspx 官方还咋github上放置了  扩展模块. 比如 web iis部署.sqlserv ...

  6. jsp中全局变量和局部变量的设置

  7. virtual hard disk

  8. 【转】基于DM8168的视频智能分析系统的设计方案

        [导读] 为了实现高清视频的智能分析功能,本文介绍了一种以TI公司的DM8168为核心的高清视频智能分析系统的设计方案,该方案从硬件设计和软件设计两个方面介绍了硬件组成.工作流程.软件架构,并 ...

  9. spring mvc 安全

    1,使用 spring form 标签 防 csrf 攻击 2,标明请求方法:RequestMethod.GET,RequestMethod.POST, PATCH, POST, PUT, and D ...

  10. python字符集选择

    # coding=utf8 或者 # -*- coding:utf-8 -*- 在python2 中默认是ASCII码的字符集,但可以引入其他的字符集  这个需要在头信息中引入: 而在python3中 ...