X-factor Chains(POJ3421 素数)
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 = X0, X1, X2, …, 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 素数)的更多相关文章
- X-factor Chains [POJ3421] [素数]
Description 给定一个正整数X, 一个长度为m的X-因子链是由m+1个整数组成的.其中 1 = X0, X1, X2, …, Xm = X 满足Xi < Xi+1 且 Xi ...
- 杭电 2136 Largest prime factor(最大素数因子的位置)
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- UVA 11610 Reverse Prime (数论+树状数组+二分,难题)
参考链接http://blog.csdn.net/acm_cxlove/article/details/8264290http://blog.csdn.net/w00w12l/article/deta ...
- HDU题解索引
HDU 1000 A + B Problem I/O HDU 1001 Sum Problem 数学 HDU 1002 A + B Problem II 高精度加法 HDU 1003 Maxsu ...
- poj3421 X-factor Chains(重复元素的全排列)
poj3421 X-factor Chains 题意:给定正整数$x(x<=2^{20})$,求$x$的因子组成的满足任意前一项都能整除后一项的序列的最大长度,以及满足最大长度的子序列的个数. ...
- HDOJ/HDU 2710 Max Factor(素数快速筛选~)
Problem Description To improve the organization of his farm, Farmer John labels each of his N (1 < ...
- HDOJ(HDU) 2136 Largest prime factor(素数筛选)
Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...
- POj3421 X-factor Chains(质因数分解+排列组合)
POj3421X-factor Chains 一开始没读懂题意,不太明白 Xi | Xi+1 where a | b means a perfectly divides into b的意思,后来才发现 ...
- Max Factor(素数筛法)题解
Max Factor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- 接入SDK
管理提醒: 本帖被 fm2010 设置为精华(2014-11-12) http://www.cocoachina.com/bbs/read.php?tid-239087.html 本帖属于Co ...
- AngularJS中的控制器示例_3
<!doctype html> <html ng-app="myApp"> <head> <script src="C:\\Us ...
- un ange frappe a ma porte
Un signe, une larme 魂牵 泪扰 un mot, une arme 字断 情烧 nettoyer les étoiles à l'alcool de mon ame 灵魂之酒眷洗 星 ...
- PowerShell_零基础自学课程_2_Powershell与Cmd以及Unix/Linux Shell
上篇文章我说道,windows为了改变用户对其console界面的诟病,于是就从windows vista开始,计划要改变这种局面,于是就有 了Powershell的出现. 1.兼容shell命令 ...
- Qt编程之信号与槽-------unresolved external symbol "public: virtual struct QMetaObject const * __thiscall XX::metaObject(void)const
原因是加入Q_OBJECT这个macro的类,被编译的时候就要用到moc这个命令,所以在VS2010中,没有加入此命令的应用,当然会出错了.所以解决办法是加,或者如果你不使用信号槽可以直接删除. 当要 ...
- 【转】Ubuntu环境下SSH的安装及使用
原文网址:http://blog.csdn.net/netwalk/article/details/12952051 SSH是指Secure Shell,是一种安全的传输协议,Ubuntu客户端可以通 ...
- C++中初始化和定义对象的语法,带括号与不带括号的区别
小记:运行环境:win xp vs2008 #include <iostream>#include <string> using std::cout;using std::c ...
- Sqrt(x) 解答
Question Implement int sqrt(int x). Compute and return the square root of x. Solution 1 -- O(log n) ...
- hdu 5344 MZL's xor(数学之异或)
Problem Description MZL loves xor very much.Now he gets an array A.The length of A ≤i,j≤n) The xor ...
- 《Swift开发指南》国内第一本Swift图书上市了
<Swift开发指南>国内第一本Swift图书上市了 既<courseId=799262">苹果Swift编程语言开发指南>视频教程地址:courseId=79 ...