poj3421 X-factor Chains
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7733 | Accepted: 2447 |
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 <iostream>
#include <algorithm> using namespace std; typedef long long ll;
ll n,ans,jie[],sum,yinzi[],tot,mul; int main()
{
jie[] = ;
for (int i = ; i <= ; i++)
jie[i] = jie[i - ] * i;
while (scanf("%lld",&n) != EOF)
{
tot = ans = sum = ;
mul = ;
memset(yinzi,,sizeof(yinzi));
for (ll i = ; i * i <= n; i++)
{
if (n % i == )
{
++tot;
while (n % i == )
{
n /= i;
yinzi[tot]++;
sum++;
}
}
}
if (n > )
{
++tot;
++sum;
yinzi[tot]++;
}
printf("%lld ",sum);
ans = jie[sum];
for (int i = ; i <= tot; i++)
mul *= jie[yinzi[i]];
ans /= mul;
printf("%lld\n",ans);
} return ;
}
poj3421 X-factor Chains的更多相关文章
- POJ3421:X-factor Chains——题解
http://poj.org/problem?id=3421 题目大意:一个数列,起始为1,终止为一给定数X,满足Xi < Xi+1 并且Xi | Xi+1. 求出数列最大长度和该长度下的情况数 ...
- POj3421 X-factor Chains(质因数分解+排列组合)
POj3421X-factor Chains 一开始没读懂题意,不太明白 Xi | Xi+1 where a | b means a perfectly divides into b的意思,后来才发现 ...
- poj3421 X-factor Chains(重复元素的全排列)
poj3421 X-factor Chains 题意:给定正整数$x(x<=2^{20})$,求$x$的因子组成的满足任意前一项都能整除后一项的序列的最大长度,以及满足最大长度的子序列的个数. ...
- X-factor Chains(POJ3421 素数)
X-factor Chains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6212 Accepted: 1928 D ...
- X-factor Chains [POJ3421] [素数]
Description 给定一个正整数X, 一个长度为m的X-因子链是由m+1个整数组成的.其中 1 = X0, X1, X2, …, Xm = X 满足Xi < Xi+1 且 Xi ...
- poj3421 X-factor Chains——分解质因数
题目:http://poj.org/problem?id=3421 好久没有独立A题了...做点水题还是有助于提升自信心的: 这题就是把 x 质因数分解,质因数指数的和 sum 就是最长的长度,因为每 ...
- 代码的坏味道(20)——过度耦合的消息链(Message Chains)
坏味道--过度耦合的消息链(Message Chains) 特征 消息链的形式类似于:obj.getA().getB().getC(). 问题原因 如果你看到用户向一个对象请求另一个对象,然后再向后者 ...
- 【转载】latch: cache buffers chains
本文转自惜分飞的博客,博客原文地址:www.xifenfei.com/1109.html,支持原创,分享知识! 当一个数据块读入sga区,相应的buffer header会被放置到hash列表上,我们 ...
- Leetcode 254. Factor Combinations
Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a func ...
随机推荐
- Nginx快速入门
本文主要介绍nginx的基本配置和操作,并介绍了一些可以完成的简单任务. 假设您已经学习过并已经安装好了nginx服务器. 如果没有,请参阅安装nginx页面(http://www.yiibai.co ...
- 《Cocos2d-x游戏开发实战精解》学习笔记3--在Cocos2d-x中播放声音
<Cocos2d-x游戏开发实战精解>学习笔记1--在Cocos2d中显示图像 <Cocos2d-x游戏开发实战精解>学习笔记2--在Cocos2d-x中显示一行文字 之前的内 ...
- Docker入门与实践之 docker安装与了解
一.Docker 概述 Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源.Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后 ...
- Python 深浅复制
(一)浅复制 复制列表最简单的方式是使用内置类型的构造方法: >>> l1 = [1, [2, 3], (4, 5)] >>> l2 = list(l1) > ...
- Python3 匿名函数
一 匿名函数 lambda函数也叫匿名函数,语法结构如下: lambda x:x+1 x --> 形参 x+1 --> 返回值,相当于return x+1 实例(Python3.0+): ...
- Java访问控制
转自:菜鸟教程
- Spring 依赖的Jar包简介
Spring 依赖的Jar包简介 Spring的依赖关系 依赖关系分组 JAR文件 说 明 ant ant.jar, ant-junit.jar, ant-launcher.jar Spring采用A ...
- P4语法(4)Control block
Control block Control block之中用于放置设计好的Table和Action. 可以把control block认为是pipeline的一个模板,之前用的v1model中就是in ...
- PAT L1-017 到底有多二
https://pintia.cn/problem-sets/994805046380707840/problems/994805121500692480 一个整数“犯二的程度”定义为该数字中包含2的 ...
- JAVA字节流(读写文件)
InputStream此抽象类是表示字节输入流的所有类的超类.需要定义 InputStream 的子类的应用程序必须始终提供返回下一个输入字节的方法. int available()返回此输入流方法的 ...