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 的因子 ...
随机推荐
- Codevs 1371 浴火银河跑运输
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description: 小 K 又在玩浴火银河了...不过这次他的目的真的是跑运输赚钱... 他想知 ...
- iOS ARC基本原理
一.ARC基本简介 ARC:Automatic Reference Counting 自动引用 完全消除了手动管理内存的烦琐,编译器会自动在适当的地方插入适当的retain.release.autor ...
- 使用JDBC向数据库中插入一条数据
原谅我是初学者,这个方法写的很烂,以后不会改进,谢谢 /** * 通过JDBC向数据库中插入一条数据 1.Statement 用于执行SQL语句的对象 1.1 通过Connection 的 * cre ...
- MySQL数据库下用户及用户权限配置
问题:使用某大腿写的远程工具管理Mysql数据库时发现所有数据能正常显示,但是无法进行删除.修改等操作. 思路:可以远程读取到数据库里的信息,说明当前主机可以远程连接数据库.却无法进行删除.修改这些操 ...
- 《Linux shell编程中 diff与vimdif的使用》RHEL6
linux比较2个文件的区别有两个命令: (1)diff (2)vimdiff cp /etc/grub.conf hello 在hello文件的末尾添加zhangsan 使用diff比较2个文件的区 ...
- 关于ionic的跨域问题
例如你的api原地址请求是 http://10.100.100.100:8080/service/, 1.那么你应该在项目内api请求改成 /service/, 注意红色部分是ionic serve ...
- AngularJS(14)-动画
AngularJS 提供了动画效果,可以配合 CSS 使用. AngularJS 使用动画需要引入 angular-animate.min.js 库. <!DOCTYPE html> &l ...
- mina socket底层主流程源码实现
一,mina的架构 mina 架构可以大致分为三部分,ioService ,ioFilterChain , IoHandler ioService:用于接受服务或者连接服务,例如socket 接收 ...
- 基于PinnedSectionListView实现联系人通讯录并且点击打电话
PinnedSectionListView具体下载地址.使用方法和注意事项:http://www.cnblogs.com/zzw1994/p/4997601.html 怎么根据联系人姓名首字符顺序读取 ...
- API地图坐标转化(批量转换坐标)
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...