HDU 4228 Flooring Tiles (反素数应用)

来源:互联网 发布:Ubuntu安装时跨硬盘 编辑:程序博客网 时间:2024/06/01 08:55

本文来自: http://blog.csdn.net/napoleon_acm/article/details/24552491

题目链接 : LINK

题目 是说, 一些 个数的方块可以 拼出 某些不同的形状的 矩形,eg: 4个方块可以拼出 1x4 , 2x2 两种。 给你 所要求的 种类数 , 求 至少要多少个小方块。

可以联想到 一个整数的 因子个数,给定n,就是求,因子数为2*n 或者2*n-1的最小整数。即,g(x)=2*n 或者2*n-1.  x约数的个数记做g(x).

反素数性质: 

性质一:一个反素数的质因子必然是从2开始连续的质数.

 

因为最多只需要10个素数构造:2,3,5,7,11,13,17,19,23,29

 

性质二:p=2^t1*3^t2*5^t3*7^t4..必然t1>=t2>=t3>=.

之后进行搜索就可以了

#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<string>#include<vector>#include<cmath>using namespace std;#define INF 1000000000typedef __int64 LL;#define N 80LL n,ans,sum;LL pri[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43};//14void dfs(LL aa,LL ss,LL time,LL lim){    if(ss>2*n) return ;    if(ss==2*n || ss==2*n-1)    {        ans=min(ans,aa);return ;    }    if(time>=14) return ;    for(LL i=1;i<=lim;i++)    {        aa*=pri[time];        dfs(aa,ss*(i+1),time+1,i);    }}int main(){#ifndef ONLINE_JUDGE    freopen ("in.txt" , "r" , stdin);#endif    while(scanf("%I64d",&n),n)    {        ans=1e18;        dfs(1,1,0,60);        printf("%I64d\n",ans);    }    return 0;}




0 0
原创粉丝点击