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 ...
随机推荐
- C语言学习中容易模糊的一些概念
1.什么叫分配内存 操作系统把某一块内存空间的使用权利分配给该程序 2.释放内存 操作系统把分配给该程序的内存空间的使用权利收回,该程序就不能再使用这块内存空间 注:释放内存空间并不是把这块内存的数据 ...
- 转:Reddit排名算法工作原理
http://www.aqee.net/how-reddit-ranking-algorithms-work/ 这是一篇继<Hacker News 排名算法工作原理>之后的又一篇关于排名算 ...
- DJANGO的HTTPRESPONSE流式输出
在项目当中遇到的问题,网上有样例代码,但都不行,后来,发现在了1.5版本之后,新的STREAMHTTPRESPONSE对象, 搞定. from django.http import HttpRespo ...
- Android下的SQLite数据库的相关操作及AndroidTestCase测试
一:创建数据库 package com.itcode.mysqlite; import android.content.Context; import android.database.sqlite. ...
- uva 10718 Bit Mask (位运算)
uva 10718 Bit Mask (位运算) Problem A Bit Mask Time Limit 1 Second In bit-wise expression, mask is a ...
- ulimit -c unlimited
tomcat 产生core日志: app:/usr/local/apache-tomcat-7.0.55_8082/logs# ulimit -a core file size (blocks, -c ...
- PHP与C++的不同
由于工作需要,需要学习一下PHP,由于3年的C++背景,在刚开始学习PHP的过程中,有些不习惯,经过一段时间的学习,总结了一些PHP与C++的不同. 1.应用场景 在谈两种语言不同的时候,首先需要了解 ...
- Apache本地服务无法自启动问题解决
问题描述: Windows不能在本地计算机启动Apache2.有关更多信息,查阅系统事件日志.如果这是非Microsoft服务,请与服务厂商联系,并参考特定服务错误代码1. 解决方案: 1.检查Apa ...
- JUnit单元测试框架的使用
http://blog.csdn.net/mao520741111/article/details/51462215 原文地址 http://www.open-open.com/lib/view/op ...
- 人物角色群体攻击判定(三)Physics.OverlapSphere(群体攻击)
使用Physics.OverlapSphere来检测不方便调试, 其他都可以. 核心代码: //检测敌人 public void CheckEnemy() { Collider[] cols = ...