题目: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. 【Flask】sqlalchemy 排序

    ### 排序:1. order_by:可以指定根据这个表中的某个字段进行排序,如果在前面加了一个-,代表的是降序排序.2. 在模型定义的时候指定默认排序:有些时候,不想每次在查询的时候都指定排序的方式 ...

  2. 如何单用户模式破解root密码&救援模式破解root密码

    学了几天Linux,终于到了装逼时刻,看看如何破译别人的root密码,哈哈哈哈..... 单用户模式破解root密码 重置Centos 7 Root密码的方式 step1 - 在启动grub菜单,选择 ...

  3. Docker容器技术-基础命令

    一.基础命令 1.运行一个镜像 [root@bogon ~]# docker run debian echo "Hello World" Unable to find image ...

  4. crm销售管理系统一

    一.环境配置 1.首先配置pip,环境变量配置 pip 9.0.1 from c:\users\administrator\envs\crm\lib\site-packages (python 3.6 ...

  5. 斯坦福机器学习视频笔记 Week7 支持向量机 Support Vector Machines

    SVM被许多人认为是最强大的“黑箱”学习算法,并通过提出一个巧妙选择的优化目标,今天最广泛使用的学习算法之一. Optimization Objective 根据Logistic Regression ...

  6. Go 外部排序-网络版

    目录结果 main.go package main import ( "NetworkSort/pipeline" "fmt" "os" & ...

  7. yum 源配置

    在 /etc/yum.repos.d 下建立一个 .repo 文件 vim  yum.repo [cd] name=cd baseurl=file:///run/media/root/RHEL-7.0 ...

  8. linux 上传scp 压缩tar命令

    1.Linux 上传scp 1)上传文件与文件夹 scp file weblogic@xx.xxx.xxx.xxx:~/songjd/ scp -r filefolder weblogic@xxx.x ...

  9. RPC与HTTP

    一.为什么需要RPC,而不是简单的HTTP接口? RPC(即Remote Procedure Call,远程过程调用),主要是基于TCP/IP协议:而HTTP服务主要是基于HTTP协议的.我们都知道H ...

  10. Java中的算术运算符

    算术运算符主要用于进行基本的算术运算,如加法.减法.乘法.除法等. Java 中常用的算术运算符: 其中,++ 和 -- 既可以出现在操作数的左边,也可以出现在右边,但结果是不同滴 例1: 运行结果: ...