从PE 108 我们可以知道,分式 1a+1b=1n 的个数 就是 1+d(n2)2 ,其中 d(n) 是n的约数的个数。、
而 PE 110 只是PE 108的加强版。用PE 108的方法 换个方式就可以了。
比如:
n=2p13p25p3......
d(n2)=N=∏i=1(2pi+1)
所以我们可以知道样例是怎么来的。
样例:
1260=22325171
d(n2)=N=5∗5∗3∗3=225
综合 1+d(n2)2 ,所以答案就是 225+12=113 。
我们要求的,只是倒过来求 n <script type="math/tex" id="MathJax-Element-10">n</script> 而已。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll primes[16]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,53};
ll ans;
void dfs(ll down, ll upper, ll build, ll cost)
{
if(cost > ans)return;
if(build > 7999999) //4000000 * 2 -1
{
ans=min(ans, cost);
return;
}
if(down>=16)return;
for(ll i = upper;i>=1;i--)
{
ll tmp=1;
for(int j = 1 ; j <= i ; j++)
{
tmp*=primes[down];
}
if((double) tmp*cost > (double)ans) continue;
dfs(down + 1, i , build * ( 2 * i + 1 ), tmp * cost);
}
}
int main()
{
ans=1e18;
dfs(0, 20, 1, 1);
printf("%lld\n", ans);
return 0;
}