Flooring Tiles 反素数

http://acm.hdu.edu.cn/showproblem.php?pid=4228

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

typedef __int64 lld;
lld p[1000];
int cnt;
lld prime[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,53,59,61};

void Gao(int fac,int limit,lld s,int k)
{
    if(fac>150 || s>((lld)1<<60)) return ;
    if(p[fac]!=-1 && p[fac]>s) p[fac]=s;
    if(p[fac]==-1)p[fac]=s;
    if(k>16)return ;
    lld temp=s;
    for(int i=1;i<=limit;i++)
    {
        temp*=prime[k];
        if(temp>((lld)1<<60))break;
        Gao(fac*(i+1),i,temp,k+1);
    }
}

int main()
{
    int i;
    int n;
    cnt=0;
    memset(p,-1,sizeof(p));
    p[1]=1;
    Gao(1,75,1,0);
    while(scanf("%d",&n)!=EOF && n)
    {
        lld ans=((lld)1<<60);
        for(i=1;i<=150;i++)
        {
        //    printf("%d  %I64d\n",i,p[i]);
            if((i+1)/2==n && p[i]!=-1)
            {
                
                if(ans>p[i])
                {
                    ans=p[i];
                }
            }
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


(转)对于任何正整数x,起约数的个数记做g(x).例如g(1)=1,g(6)=4.
如果某个正整数x满足:对于任意i(0<i<x),都有g(i)<g(x),则称x为反素数.
现在给一个N,求出不超过N的最大的反素数.
比如:输入1000  输出 840
思维过程:
求[1..N]中约数在大的反素数-->求约数最多的数
如果求约数的个数 756=2^2*3^3*7^1
(2+1)*(3+1)*(1+1)=24
基于上述结论,给出算法:按照质因数大小递增顺序搜索每一个质因子,枚举每一个质因子
为了剪枝:
性质一:一个反素数的质因子必然是从2开始连续的质数.
因为最多只需要10个素数构造:2,3,5,7,11,13,17,19,23,29
性质二:p=2^t1*3^t2*5^t3*7^t4.....必然t1>=t2>=t3>=....
http://apps.hi.baidu.com/share/detail/16212584


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WishingBone plans to decorate his hexagon-shaped room with unique flooring patterns. First he divides it into triangles, and colors them with different colors. Now that he has got a satisfactory pattern, he uses small rugs to cover the floor. The rugs sold at shops are diamond-shaped; exact the shape of two adjacent triangles. He is not willing to cut any of them. Different colored rugs are labeled different price. And he does care about the price - he cares about the most expensive rugs that he should use to finish the covering. Input There are multiple tests, for each test: The first line is an integer specifying the side of his room (1 <= n <= 50). The following 2n lines with the pattern of the room, with upper-case letters denoting different colors. So there are at most 26 colors. Since the room is considerably large and sometimes needs pillars to support the ceiling, some triangles are marked with '.' rather than a letter. Such triangles are not to be covered. The following line contains one integer m (1 <= m <= 351) - number of rugs in the shop. The following m lines contains one type of rug (with two upper-case letters) and its price p (1 <= p <= 100000). There will not be duplicate items listed, that is, if AB is listed, BA will not appear. You may assume the number of each type to be infinite. Output One line for each test, the price of the most expensive rugs used. Of course, you have to minimize this value. If there is no solution to the problem, print a 0.
最新发布
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值