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. post 报文请求接口方法

    /// <summary> /// post 报文到接口服务器 /// </summary> /// <param name="targetUri"& ...

  2. Nginx 内置变量,细化规则,真实IP获取及限制连接请求

    希望下周测试之后能用起来!!!感觉很有用的. http://www.bzfshop.net/article/176.html http://www.cr173.com/html/19761_1.htm ...

  3. HDU 4411 Arrest

    http://www.cnblogs.com/jianglangcaijin/archive/2012/09/24/2700509.html 思路: S->0 流量为K费用0 0->i 流 ...

  4. 粗窥STARTUP.A51和INIT.A51

    也许大家曾经注意过使用Keil C51来编译链接生成目标代码之后,在我们的主程序之前有些代码不是我们写的,它们从哪里来的? Keil C51的\C51\LIB目录下有STARTUP.A51和INIT. ...

  5. DEVExpress For WPF 中GridControl如何实现滚动分页(延迟查询)

    在显示大量数据时一般采用分页显示,但是最近用户需要滚动显示,那么问题来了,滚动显示要求将数据全部查询回来,这显然会导致显示速度很慢. 好在想到一种方式,就是当用户滚动鼓动条的时候再查询下面的数据.好吧 ...

  6. android批量文件上传(android批量图片上传)

    项目中多处用到文件批量上传功能,今天正好解决了此问题,在此写出来,以便日后借鉴. 首先,以下架构下的批量文件上传可能会失败或者不会成功:   1.android客户端+springMVC服务端:服务端 ...

  7. windows nfs server for linux

    摘要 在开发嵌入式系统的过程中,为了方便调试与文件共享,需要使用到nfs,即网络文件系统,这位板子的调试测试带来了很大的方便.之前在linux系统下开发,与ARM11核心板 linux系统对接共享也比 ...

  8. DirectX 初始化DirectX(手写和红龙书里面的方式)

    上次介绍了如何初始化Direct3D,这次手写一次初始化代码,都是一样的方式不过看起来整洁一点. 创建一个Win32空项目添加一个空类增加以下代码即可. #include "CreateDe ...

  9. Maven中pom.xml常用元素说明

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  10. jQuery插件Jeditable的使用(Struts2处理)

        Jeditable - Edit In Place Plugin For jQuery,是一款JQuery就地编辑插件.也就是在页面直接点击需要编辑的内容,就会自动变成文本框进行编辑.它的官方 ...