BZOJ 1053: [HAOI2007]反素数ant【枚举+打表】
1053: [HAOI2007]反素数ant
Time Limit: 10 Sec Memory Limit: 162 MB
Description
对于任何正整数x,其约数的个数记作g(x)。例如g(1)=1、g(6)=4。如果某个正整数x满足:
,则称x为反质数。例如,整数1,2,4,6等都是反质数。现在给定一个数N,你能求出不超过N的最大的反质数么?
Input
一个数N(1<=N<=2,000,000,000)。
Output
不超过N的最大的反质数。
Sample Input
1000
Sample Output
840
题解
看到这题,首先发现答案很少,so打表。。。
代码如下(打表):
#include<cmath>
#include<cstdio>
using namespace std;
int stk[1005],ans[1005],top;
int sushu(int x){
int num=0,len=sqrt(x);
for(int i=1;i<=len;i++)
if(!(x%i)) num+=2;
if(len*len==x) num--;
return num;
}
int main(){
freopen("prob.cpp","w",stdout);
for(int i=61261200;i<=2000000000;i++){
int now=sushu(i);
if(ans[top]<now) ans[++top]=now,stk[top]=i,printf("%d,",top,stk[top]);
}
return 0;
}
代码:
#include<cstdio>
using namespace std;
const int ans[505]={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,2001000000};
int n;
int main(){
scanf("%d",&n);
for (int i=0;;i++) if (ans[i]>n){printf("%d\n",ans[i-1]);return 0;}
return 0;
}
QWQ