[bzoj1053][HAOI2007]反素数ant

题意 对于任何正整数x,其约数的个数记作g(x)。例如g(1)=1、g(6)=4。如果某个正整数x满足:g(x)>g(i) 0<i<x ,则称x为反质数。给定n,求小等于n的最大反质数。

正确题解:每个数用的质数肯定是连续的,并且数量递减,所以直接搜索。

非常正确错误题解:打表。对于比较大的答案,肯定有用到2.3.5等小质数,剪枝一下应该可以在考试时间内打完吧......

#include<iostream>
#include<cstdio>
using namespace std;
const int x[68]={1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,1260,1680,2520,5040,7560,10080,15120,20160,25200,27720,45360,50400,55440,83160,110880,166320,221760,277200,332640,498960,554400,665280,720720,1081080,1441440,2162160,2882880,3603600,4324320,6486480,7207200,8648640,10810800,14414400,17297280,21621600,32432400,36756720,43243200,61261200,73513440,110270160,122522400,147026880,183783600,245044800,294053760,367567200,551350800,698377680,735134400,1102701600,1396755360};
int n;
int main()
{
    scanf("%d",&n);int l=0,r=67,mid,ans;
    while(l<=r){mid=(l+r)>>1;if(x[mid]<=n)ans=x[mid],l=mid+1;else r=mid-1;}
    cout<<ans;
    return 0;
}

 

posted @ 2017-03-01 18:02  FallDream  阅读(158)  评论(0编辑  收藏  举报