【BZOJ1053】【DFS】【打表】[HAOI2007]反素数ant 题解

Description

  对于任何正整数x,其约数的个数记作g(x)。例如g(1)=1、g(6)=4。如果某个正整数x满足:g(x)>g(i) 0

#include 

using namespace std;

int n,num[100];

int main() {
    num[1] = 1396755360;
    num[2] = 1102701600;
    num[3] = 735134400;
    num[4] = 698377680;
    num[5] = 551350800;
    num[6] = 367567200;
    num[7] = 294053760;
    num[8] = 245044800;
    num[9] = 183783600;
    num[10] = 147026880;
    num[11] = 122522400;
    num[12] = 110270160;
    num[13] = 73513440;
    num[14] = 61261200;
    num[15] = 43243200;
    num[16] = 36756720;
    num[17] = 32432400;
    num[18] = 21621600;
    num[19] = 17297280;
    num[20] = 14414400;
    num[21] = 10810800;
    num[22] = 8648640;
    num[23] = 7207200;
    num[24] = 6486480;
    num[25] = 4324320;
    num[26] = 3603600;
    num[27] = 2882880;
    num[28] = 2162160;
    num[29] = 1441440;
    num[30] = 1081080;
    num[31] = 720720;
    num[32] = 665280;
    num[33] = 554400;
    num[34] = 498960;
    num[35] = 332640;
    num[36] = 277200;
    num[37] = 221760;
    num[38] = 166320;
    num[39] = 110880;
    num[40] = 83160;
    num[41] = 55440;
    num[42] = 50400;
    num[43] = 45360;
    num[44] = 27720;
    num[45] = 25200;
    num[46] = 20160;
    num[47] = 15120;
    num[48] = 10080;
    num[49] = 7560;
    num[50] = 5040;
    num[51] = 2520;
    num[52] = 1680;
    num[53] = 1260;
    num[54] = 840;
    num[55] = 720;
    num[56] = 360;
    num[57] = 240;
    num[58] = 180;
    num[59] = 120;
    num[60] = 60;
    num[61] = 48;
    num[62] = 36;
    num[63] = 24;
    num[64] = 12;
    num[65] = 6;
    num[66] = 4;
    num[67] = 2;
    num[68] = 1;
    num[69] = 0;
    scanf("%d",&n);
    for(int i = 1; i <= 69; i++) if(n >= num[i]) { printf("%d\n",num[i]); return 0; }
}

dfs:


#include
using namespace std;
int i,n,j;
long long ans_num,ans_sum;
int prime[11]={0,2,3,5,7,11,13,17,19,23,29};
void dfs(long long sum,long long num,long long now_pri,long long now_sum,long long now_num)
{
  long long newsum=sum*now_sum;if (newsum>n) return;
  long long newnum=num/now_num*(now_num+1);
  if (newnum>ans_num) {ans_num=newnum;ans_sum=newsum;}
  else if (newnum==ans_num&&newsum1);
  for (int i=now_pri+1;i<=10;i++)
    dfs(newsum,newnum,i,prime[i],1);
}
int main()
{
  scanf("%ld",&n);ans_sum=1;
  if (n>1) dfs(1,1,1,2,1);
  printf("%ld",ans_sum);
}

你可能感兴趣的:(BZOJ,搜索,乱搞)