zoukankan      html  css  js  c++  java
  • bzoj1053: [HAOI2007]反素数ant

    1053: [HAOI2007]反素数ant

    题目:传送门 

    题解:

       首先要知道一个知识点:

       一个数的因数个数=所有不同质因数的次数+1后相乘

       假设:x=p1^x1*p2^x2*p3^x3

       那么x的因子个数就是(x1+1)*(x2+1)*(x3+1)

       那么依据题目,我们肯定是需要更多的因数,那就打个dfs吧

    代码:

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<cstdlib>
     4 #include<cmath>
     5 #include<algorithm>
     6 #define qread(x) x=read()
     7 using namespace std;
     8 typedef long long LL;
     9 inline LL read()
    10 {
    11     LL f=1,x=0;char ch;
    12     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    13     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
    14     return f*x;
    15 }
    16 LL n;
    17 LL p[15]={0,2,3,5,7,11,13,17,19,23,29,31,37};
    18 LL s[1100];int ans,y;
    19 void dfs(int x,int sum,LL multi)
    20 {
    21     if(x>12)return ;
    22     if(sum>y || sum==y && multi<ans)
    23     {
    24         ans=multi;
    25         y=sum;
    26     }
    27     s[x]=0;
    28     while(multi*p[x]<=n && s[x]<s[x-1])
    29     {
    30         s[x]++;
    31         multi*=p[x];
    32         LL next=sum*(s[x]+1);
    33         dfs(x+1,next,multi);
    34     }
    35 }
    36 int main()
    37 {
    38     qread(n);ans=y=0;
    39     s[0]=100000;
    40     dfs(1,1,1);
    41     printf("%lld
    ",ans);
    42     return 0;
    43 }
  • 相关阅读:
    补充缺失日期及对应数据
    通过拆分字段优化SQL
    left join 改写标量子查询
    对数据按组排序
    注册通用验证用户filter
    asp.net mvc FormsAuthentication一些问题
    il code swtich
    C# Equals
    Linq源代码阅读
    dotnet il editor 调试 iis 程序
  • 原文地址:https://www.cnblogs.com/CHerish_OI/p/8192835.html
Copyright © 2011-2022 走看看