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. HTML动画(难点)

    animation-delay这个属性是规定动画开始前等待几秒才开始.本来是很好理解的,但是当时就有个疑问:假如我的动画是连续执行好多次的情况下的话,是第一次执行前才会延迟还是每次执行前都会延迟呢?答 ...

  2. C语言--位运算符

    一.位运算符 1.按位与:& 1> 功能 * 只有对应的两个二进制位为1时,结果位才为1,否则为0 * 举例:10用二进制表示为1010,  7用二进制表示为0111.对两个数值进行&a ...

  3. Spark添加/更改集群节点需要修改的配置文件

    笔记:在配置好了spark后,如果需要添加/删除一个结点需要修改如下配置文件 cd $HADOOP/etc/hadoop 进入hadoop配置文件夹下 修改 slaves,将对应的节点添加/删除 修改 ...

  4. Codeforces Round #277 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...

  5. php缓存技术常用函数

    OB缓存系列函数(输出缓存) ob_start()函数:打开输出缓冲区. 函数格式 ob_start(void) 说明:当缓冲区激活时,所有来自PHP程序的非文件头信息均不会发送,而是保存在ob缓冲区 ...

  6. Django 反向生成 从数据库生成Model

    Django 反向生成 从数据库生成Model 使用Django生成Model python manage.py inspectdb或python manage.py inspectdb > m ...

  7. Quartz.net Cron表达式

    由7段构成:秒 分 时 日 月 星期 年(可选)"-" :表示范围  MON-WED表示星期一到星期三"," :表示列举 MON,WEB表示星期一和星期三&qu ...

  8. LeetCode_Path Sum II

    Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...

  9. 读论文系列:Nearest Keyword Search in XML Documents中使用的数据结构(CT、ECT)

    Reference: [1]Y. Tao, S. Papadopoulos, C. Sheng, K. Stefanidis. Nearest Keyword Search in XML Docume ...

  10. Hibernate逆向工程全过程

    前提你已经创建好了数据库,按如下操作进行: 1.添加hibernate.cfg.xml 在src下-->new-->other--->hibernate-->选择“Hibern ...