poj 3421 X-factor Chains——质因数分解
题目:http://poj.org/problem?id=3421
记忆化搜索竟然水过去了。仔细一想时间可能有点不对,但还是水过去了。
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
const int N=(<<)+;
int n;
ll a[N],f[N];
void find(int x)
{
if(a[x])return;
a[x]=;
for(ll i=;i*i<=x;i++)
if(x%i==)
{
find(i);find(x/i);
ll tmp=a[x];
a[x]=max(a[x],max(a[i],a[x/i])+);
if(a[x]!=tmp)f[x]=;
if(a[i]==a[x]-)f[x]+=f[i];
if(i!=x/i&&a[x/i]==a[x]-)f[x]+=f[x/i];//i!=x/i
}
if(!f[x])f[x]=;
}
int main()
{
while(scanf("%d",&n)==)
{
find(n);
printf("%lld %lld\n",a[n],f[n]);
}
return ;
}
然后发现是质因数分解。
可以理解成需要乘一个数才能进一步,为了走最长的,就是乘最小的,也就是一个质因数。
方案数就是一堆组合数相乘啦。不敢预处理,现求阶乘也没爆。
没错,仔细一想最多只有20个质因数,因为是log的。
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
const int N=(<<)+,M=;
int n,p[M],k[M],tot,sum;
ll ans;
ll C(int n,int m)
{
ll ret=;
for(int i=n-m+;i<=n;i++)ret*=i;
for(int i=;i<=m;i++)ret/=i;
return ret;
}
int main()
{
while(scanf("%d",&n)==)
{
ans=;sum=;tot=;
for(int i=;i*i<=n;i++)
if(n%i==)
{
p[++tot]=i;k[tot]=;
while(n%i==)n/=i,k[tot]++;
sum+=k[tot];
}
if(n>)p[++tot]=n,k[tot]=,sum++;
printf("%d ",sum);
for(int i=;i<=tot;i++)
{
ans*=C(sum,k[i]);sum-=k[i];
}
printf("%lld\n",ans);
}
return ;
}
poj 3421 X-factor Chains——质因数分解的更多相关文章
- POj3421 X-factor Chains(质因数分解+排列组合)
POj3421X-factor Chains 一开始没读懂题意,不太明白 Xi | Xi+1 where a | b means a perfectly divides into b的意思,后来才发现 ...
- POJ 1845 Sumdiv#质因数分解+二分
题目链接:http://poj.org/problem?id=1845 关于质因数分解,模板见:http://www.cnblogs.com/atmacmer/p/5285810.html 二分法思想 ...
- POJ 2429 long long 质因数分解
GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16206 Accepted: ...
- Poj 1401 Factorial(计算N!尾数0的个数——质因数分解)
一.Description The most important part of a GSM network is so called Base Transceiver Station (BTS). ...
- algorithm@ 大素数判定和大整数质因数分解
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...
- 数学概念——J - 数论,质因数分解
J - 数论,质因数分解 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- hdu1405 第六周J题(质因数分解)
J - 数论,质因数分解 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Desc ...
- HDU 1045(质因数分解)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description Tomor ...
- [学习笔记] Miller-Rabin质数测试 & Pollard-Rho质因数分解
目录 Miller-Rabin质数测试 & Pollard-Rho质因数分解 Miller-Rabin质数测试 一些依赖的定理 实现以及正确率 Pollard-Rho质因数分解 生日悖论与生日 ...
随机推荐
- linux下安装casperjs 开发运行环境
casperjs是一个基于phantomjs的测试框架,使用python进行操作,所以一个完整的casperjs环境需要安装phantomjs和python. 1 phantomjs安装 到官网下载最 ...
- Java 类及类的构造方法
类 类是一个模子,确定对象将会拥有的特性(属性)和行为(方法). 类的特点 类时对象的类型 具有相同属性和方法的一组对象的集合 构造方法 作用就是对类进行初始化. 如果你没有定议任何构造方法的形式,J ...
- win10系统下载地址
Win10正式版微软官方原版ISO系统镜像下载: Win10正式版32位简体中文版(含家庭版.专业版) 文件名: cn_windows_10_multiple_editions_x86_dvd_684 ...
- poj 1961 Period 【KMP-next前缀数组的应用】
题目地址:http://poj.org/problem?id=1961 Sample Input 3 aaa 12 aabaabaabaab 0 Sample Output Test case #1 ...
- python实现免密码登录lunx服务器
import paramikoimport oshostname='192.168.76.10'username='root'# password='123456'ssh=paramiko.SSHCl ...
- SEM竞价数据基本分析方法
今天我们从账户数据表现来看一看怎样通过数据分析,判断账户出现的问题及解决思路.也欢迎大家提出意见,共同讨论进步. 首先我们从关键词报告来分析数据: 以上图数据为例.(设定该行业CPC均价为8) 先说下 ...
- how to use Inspector in fiddler
打开fiddler之后,会自动捕获本机的http请求,以列表的形式显示在左侧 双击左侧列表中的某一个request,右侧会自动切换到Inspectors窗口. 右侧上半部分是request的raw G ...
- 如何用wamp配置多域名虚拟目录
一.前言 自从重装了最新版wamp64后就不可用了,下面来介绍我的解决方法,两者均可尝试,差别并不大! 二.配置虚拟主机 1.首先打开apache的配置文件httpd.conf (路径\wamp64\ ...
- review29
数组流 流的源和目的地除了可以是文件外,还可以是计算机内存. 1.字节数组流 字节数组输入流ByteArrayInputStream和字节数组输出流ByteArrayOutputStream分别使用字 ...
- dom 兼容性问题 2 offset
offsetParent : 离当前节点最近的具有定位属性的祖先节点. 如果所有祖先节点都没有定位属性: 对于一个有定位属性的元素: ie6.7 : offsetParent 是 html 节 ...