POJ 3421
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 5111 | Accepted: 1622 |
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
Source
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std; #define maxn (1 << 20) + 5 typedef long long ll; int x,len = ;
bool prime[maxn];
int ele[]; ll cal(int x) {
ll ans = ;
for(int i = ; i <= x; i++) ans *= i; return ans;
} void init() {
for(int i = ; i <= maxn - ; i++) {
prime[i] = i % || i == ;
} for(int i = ; i * i <= maxn - ; i++) {
if(!prime[i]) continue;
for(int j = i; j * i <= maxn - ; j++) {
prime[j * i] = ;
}
} len = ;
for(int i = ; i <= maxn - ; i++) {
if(prime[i])
ele[len++] = i;
} }
int main() {
//freopen("sw.in","r",stdin); init(); while(~scanf("%d",&x)) {
if(prime[x]) {
printf("1 1\n");
} else {
int ans1 = ,len2 = ;
ll ans2 = ;
int num[];
for(int i = ; i < len && ele[i] <= x && x != ; i++) {
int sum = ;
if(x % ele[i] == ) {
while(x % ele[i] == ) {
ans1++;
sum++;
x /= ele[i];
}
num[len2++] = sum;
} } ans2 = cal(ans1);
for(int i = ; i < len2; i++) {
ans2 /= cal(num[i]);
}
printf("%d %I64d\n",ans1,ans2); } } return ;
}
POJ 3421的更多相关文章
- poj 3421 X-factor Chains——质因数分解
题目:http://poj.org/problem?id=3421 记忆化搜索竟然水过去了.仔细一想时间可能有点不对,但还是水过去了. #include<iostream> #includ ...
- POJ 3421分解质因数
X-factor Chains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7375 Accepted: 2340 D ...
- Mathematics:X-factor Chains(POJ 3421)
X链条 题目大意,从1到N,1 = X0, X1, X2, …, Xm = X中间可以分成很多数,另Xi < Xi+1 Xi 可以整除Xi+1 ,求最大长度m和m长度的链有多少条 思路: 很简单 ...
- POJ 3421 X-factor Chains
线型素数筛+质因素分解+组合数. AC后发现这样做效率有点低..766ms. #include<stdio.h> #include<string.h> #include< ...
- POJ 3421 X-factor Chains (因式分解+排列组合)
题意:一条整数链,要求相邻两数前一个整除后一个.给出链尾的数,求链的最大长度以及满足最大长度的不同链的数量. 类型:因式分解+排列组合 算法:因式分解的素因子个数即为链长,链中后一个数等于前一个数乘以 ...
- POJ 3421 X-factor Chains | 数论
题意: 给一个x,求最长的排列满足开头是1,结尾是x,前一个数是后一个数的因子 输出长度和这样序列的个数 题解: 把x分解质因数,质因数个数就是答案,接下来考虑怎么求个数 显然这是一个可重集合全排列问 ...
- POJ 3421 X-factor Chains(构造)
这条链依次乘一个因子.因为n<2^20,sqrt(n)分解因子,相同的因子相对顺序取一个. 组合公式计算一下就好. #include<cstdio> #include<iost ...
- ProgrammingContestChallengeBook
POJ 1852 Ants POJ 2386 Lake Counting POJ 1979 Red and Black AOJ 0118 Property Distribution AOJ 0333 ...
- 一本通1628X-factor Chain
1628:X-factor Chain 时间限制: 1000 ms 内存限制: 524288 KB [题目描述] 原题来自 POJ 3421 输入正整数 x,求 x 的大于 1 的因子 ...
随机推荐
- 一些常用的字符串hash函数
unsigned int RSHash(const std::string& str) { unsigned int b = 378551; unsigned int a = 63689; u ...
- 在Java中怎样把数组转换为ArrayList?
翻译自:How to Convert Array to ArrayList in Java? 本文分析了Stack Overflow上最热门的的一个问题的答案,提问者获得了很多声望点,使得他得到了在S ...
- VMware虚拟机中设置端口映射(转载)
VMware Workstation提供了两种虚拟机上网方式,一种bridge,一种NAT,bridge可以获得公网地址,而NAT只能是内网地址了. NAT相当于把主机当成了一个NAT转换器,我们可以 ...
- Android AdapterView.OnItemSelectedListener
AdapterView.OnItemSelectedListener Summary Public Methods abstract void onItemSelected(AdapterView&l ...
- CSS精粹之布局技巧
1.若有疑问立即检测 在出错时若能对原始代码做简单检测可以省去很多头痛问题.W3C对于XHTML与CSS都有检测工具可用,请见http://validator.w3.org 请注意,在文件开头的错误, ...
- Google Ajax Library API使用方法(JQuery)
Google Ajax Library API使用方法 1.传统方式: <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7. ...
- ASP.NET MVC 应用程序的安全性,看一眼你就会了
1.使用Authorize特性登陆对于我们开发程序而言,基本上都是要求角色成员使用Authorize特性,比如,对于管理员而言角色是Admin,对于登陆注册登陆用户而言是User那么我们在用户登陆的时 ...
- CentOS 7 yum nginx MySQL PHP 简易环境搭建
用centos自带的yum源来安装nginx,mysql和php,超级方便,省去编译的麻烦,省去自己配置的麻烦,还能节省非常多的时间. 我们先把yum源换成国内的阿里云镜像源(当然不换也可以),先备份 ...
- sql中的系统表sysobjects以及如何查看sql语句的执行时间
使用sysobjects可以快速查看数据库中表.视图.存储过程.触发器.约束等的信息. 大牛文章:http://www.cnblogs.com/atree/p/SQL-Server-sysobject ...
- 帝国cms后台不停的登录成功
http://bbs.phome.net/showthread-13-305985-1.html 感谢各位的支持与帮助! e/data/adminlogin目录权限没有问题 问题在:计划任务中,刷新自 ...