标签:span ref for href auth iostream ring math coder
t次询问,每次给你一个数n,求在[1,n]内约数个数最多的数的约数个数
\(t \le 500,n \le 10^{19}\)
首先可以想到将n质因数分解。即\(n= \prod\limits_{i=1}^n{a_i}^{p^i}\)
答案就是\(\prod\limits_{i=1}^n{p_i+1}\)
然后我们要想办法让n最小,答案最大。
可以发现,如果存在\(a_i < a_j \&\& p_i < p_j\),那么交换\(p_i,p_j\)一定会更优秀。
也就是说对于任意的\(a_i < a_j\)都有\(p_i \ge p_j\)
然后搜索即可
/*
* @Author: wxyww
* @Date: 2019-05-31 19:26:20
* @Last Modified time: 2019-05-31 21:29:54
*/
#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<ctime>
using namespace std;
typedef long long ll;
const int N = 100100;
#define int ll
ll read() {
ll x=0,f=1;char c=getchar();
while(c<'0'||c>'9') {
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9') {
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
ll dis[N],vis[N],js;
void eur() {
int n = N - 100;
for(int i = 2;i <= n;++i) {
if(!vis[i]) dis[++js] = i;
for(int j = 1;j <= js && 1ll * dis[j] * i <= n;++j) {
vis[dis[j] * i] = 1;
if(i % dis[j] == 0) break;
}
}
return;
}
ll ans;
void solve(ll nans,ll now,ll x,ll lst) {
for(int i = 1;i <= lst && x >= dis[now];++i)
solve(nans * (i + 1),now + 1,x /= dis[now],i);
ans = max(ans,nans);
}
signed main() {
int T = read();
eur();
while(T--) {
ll x = read();
ans = 0;
solve(1,1,x,10000);
printf("%lld\n",ans);
}
return 0;
}
标签:span ref for href auth iostream ring math coder
原文地址:https://www.cnblogs.com/wxyww/p/nowcoder907B.html