zoukankan      html  css  js  c++  java
  • 洛谷 P1463 [HAOI2007]反素数

    https://www.luogu.org/problemnew/show/P1463

    注意到答案就是要求1-n中约数最多的那个数(约数个数相同的取较小的)

    根据约数个数的公式,在约数个数相同的情况下,如果各个质因子是从2开始的连续质数且指数不下降,那么一定可以得到最小的结果

    玄学爆搜即可。。。

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<cstring>
     4 #include<vector>
     5 #include<bitset>
     6 using namespace std;
     7 #define fi first
     8 #define se second
     9 #define mp make_pair
    10 #define pb push_back
    11 typedef long long ll;
    12 typedef unsigned long long ull;
    13 typedef pair<ll,ll> pll;
    14 const ll N=100000;
    15 ll n;
    16 ll prime[100100],len;
    17 pll ans;
    18 bool nprime[100100];
    19 void dfs(ll x,ll k,ll p,ll maxn)
    20 {
    21     if(ans.se<k||(ans.se==k&&ans.fi>x))    ans=pll(x,k);
    22     if(maxn==0)    return;
    23     ll i,now=1;
    24     for(i=0;i<=maxn;i++)
    25     {
    26         if(now*x>n)    break;
    27         dfs(now*x,k*(i+1),p+1,i);
    28         now*=prime[p];
    29     }
    30 }
    31 int main()
    32 {
    33     ll i,j;
    34     scanf("%lld",&n);
    35     for(i=2;i<=N;i++)
    36     {
    37         if(!nprime[i])    prime[++len]=i;
    38         for(j=1;j<=len&&i*prime[j]<=N;j++)
    39         {
    40             nprime[i*prime[j]]=1;
    41             if(i%prime[j]==0)    break;
    42         }
    43     }
    44     dfs(1,1,1,233333333);
    45     printf("%lld",ans.fi);
    46     return 0;
    47 }
  • 相关阅读:
    【BZOJ2287】消失之物
    【NOI2001】炮兵阵地
    【SCOI2005】互不侵犯
    【USACO2007 nov glod】玉米田
    【NOIP模拟】航班
    【NOIP模拟】闲荡
    【NOIP模拟】军队调遣
    树形地铁系统
    矩阵
    完美的集合(题解)
  • 原文地址:https://www.cnblogs.com/hehe54321/p/9388777.html
Copyright © 2011-2022 走看看