TOJ 4115 Find the number

I forget mark value = minValue ,so I get WA one day.So sad a story.

The portal:http://acm.tju.edu.cn/toj/showp4115.html

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>

double minValue;
long long Mod = 1e9 + 7;
int prime[14] = {3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int best[14],temp[14];

void DFS(const int & depth,const int & now,const double & value){
if(value >= minValue){
return;
}
if(now == 1){
if(value < minValue){
minValue = value ;
for(int i=0;i<14;i++){
best[i] = temp[i];
}
}
return ;
}
if(depth >= 14) return ;
for(int i=1;i<=sqrt(now);i++){
if(now % i == 0){
int t = i;
if(t > 1){
temp[depth] = t - 1;
DFS(depth+1,now/t,value+(t-1)*log(prime[depth]));
temp[depth] = 0;
}
t = now / i;
if(t > 1){
temp[depth] = t - 1;
DFS(depth+1,now/t,value+(t-1)*log(prime[depth]));
temp[depth] = 0;
}
}
}
}

long long Quick_pow(const int &x,int k){
long long ret = 1,base = x;
while(k){
if(k&1){
ret = (ret * base) % Mod;
}
base = (base * base) % Mod;
k >>= 1;
}
return ret;
}

int main(void){
//freopen("a.in","r",stdin);
int n;
while(scanf("%d",&n)!=EOF){
memset(best,0,sizeof(best));
memset(temp,0,sizeof(temp));
minValue = (n-1)*log(3.0);
best[0] = n - 1;
DFS(0,n,0);
long long ans = 1;
for(int i=0;i<14;i++){
ans = (ans * Quick_pow(prime[i],best[i])) % Mod;
}
printf("%lld\n",ans);
}
return 0;
}


• 本文已收录于以下专栏：

举报原因： 您举报文章：TOJ 4115 Find the number 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)