题目: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——质因数分解的更多相关文章

  1. POj3421 X-factor Chains(质因数分解+排列组合)

    POj3421X-factor Chains 一开始没读懂题意,不太明白 Xi | Xi+1 where a | b means a perfectly divides into b的意思,后来才发现 ...

  2. POJ 1845 Sumdiv#质因数分解+二分

    题目链接:http://poj.org/problem?id=1845 关于质因数分解,模板见:http://www.cnblogs.com/atmacmer/p/5285810.html 二分法思想 ...

  3. POJ 2429 long long 质因数分解

    GCD & LCM Inverse Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16206   Accepted: ...

  4. Poj 1401 Factorial(计算N!尾数0的个数——质因数分解)

    一.Description The most important part of a GSM network is so called Base Transceiver Station (BTS). ...

  5. algorithm@ 大素数判定和大整数质因数分解

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...

  6. 数学概念——J - 数论,质因数分解

    J - 数论,质因数分解 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  7. hdu1405 第六周J题(质因数分解)

    J - 数论,质因数分解 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Desc ...

  8. HDU 1045(质因数分解)

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description Tomor ...

  9. [学习笔记] Miller-Rabin质数测试 & Pollard-Rho质因数分解

    目录 Miller-Rabin质数测试 & Pollard-Rho质因数分解 Miller-Rabin质数测试 一些依赖的定理 实现以及正确率 Pollard-Rho质因数分解 生日悖论与生日 ...

随机推荐

  1. Raspberry Pi开发之旅-实现云平台监控

    一.基本设置 1 sudo raspi-config 移动到第五项“Enable Camera”,回车进入,按tab键切换到“Enable”回车确认.回到主菜单,tab键切换到“Finish”回车确认 ...

  2. Python编程-异常处理

    一.错误和异常 1.程序中难免出现错误,而错误分成两种 (1)语法错误(这种错误,根本过不了python解释器的语法检测,必须在程序执行前就改正) #语法错误示范一 if #语法错误示范二 def t ...

  3. PHP实现链式操作

    什么是链式操作 我们经常会在一些应用框架中看到如下代码: $db = new Database; $db->where('cid = 9')->order('aid desc')-> ...

  4. Vue.js学习笔记 第一篇 数据绑定

    双花括号文本插值 先来个最简单的例子,看完之后立马会用Vue了,是不是很有成就感 <!DOCTYPE html> <html> <head> <meta ch ...

  5. linux文件系统实现原理简述【转】

    本文转载自:https://blog.csdn.net/eleven_xiy/article/details/71249365 [摘要] [背景] [正文] [总结]   注意:请使用谷歌浏览器阅读( ...

  6. 在Linux系统下使用Docker以及Weave搭建Nginx反向代理

    Hi, 今天我们将会学习如何使用 Weave 和 Docker 搭建 Nginx 的反向代理/负载均衡服务器.Weave 可以创建一个虚拟网络将 Docker 容器彼此连接在一起,支持跨主机部署及自动 ...

  7. MSSqlserver的锁模式介绍

    一 SQL Server 锁类型的说明 在SQL Server数据库中加锁时,除了可以对不同的资源加锁,还可以使用不同程度的加锁方式,即有多种模式,SQL Server中锁模式包括: 1.共享锁(S) ...

  8. linux运维面试题1

    一.填空题 1. 在Linux 系统 中,以文件方式访问设备 . 2. Linux 内核引导时,从文件/etc/fstab中读取要加载的文件系统 . 3. Linux 文件系统中每个文件用indoe节 ...

  9. springmvc文件上传的基本描述

    SpringMVC的文件上传,底层也是使用的Apache的Commons-fileupload 可以分为三步: 1.导入依赖包 <!-- 文件上传的依赖 --> <dependenc ...

  10. Windows batch: call more than one command in a FOR loop?

    https://stackoverflow.com/questions/2252979/windows-batch-call-more-than-one-command-in-a-for-loop U ...