Portal: Click to open link
Obviously there will be a lot of repetitive calculations, so it's easy to think of the repulsion theorem.
We set Dp[i] to represent the total number of classes that can be expressed as m^i (i>1) and I is the largest case in which the number can be represented
For example, when 27 is split into M^k, the K maximum can be expressed as 3, so 27 is the number of dp[3]
1 We do not consider it for the time being, do not put it in any kind
Because K>1, so K is at least 2, Max is 2^k=n time, so K max equals log2 (N), so K very small
First, find out the maximum approximate position of K
Then began to beg Dp[i]. The method is as follows:
First of all, what is in the 1~n can be split into m^i, using the POW function can be calculated, temporarily recorded as Dp[i]
In accordance with the requirements of dp[i], it must also be ruled out that K is not currently the largest case, the equivalent of the allowance, as follows
Dp[i]=dp[i]-dp[2*i]-dp[3*i]-dp[4*i]-.......
When this is done, Dp[i] is the total number of classes that can be expressed as m^i (i>1) and I is the largest case in which the number can be represented.
The final answer is the maximum value of dp[2]+dp[3]+....+dp[k], plus the 1 we didn't think about before.
#include <map> #include <set> #include <cmath> #include <stack> #include <queue> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <cstring># include<iostream> #include <algorithm> #include <functional> #define FIN freopen ("Input.txt", "R", stdin) #define FOUT freopen ("Output.txt", "w+", stdout) using namespace Std;typedef long long ll;typedef pair<int, int > pii;const int MX = 1e3 + 5;const double exps = 1e-8; ll Dp[mx];int Main () { ll n;//fin; while (~SCANF ("%i64d", &n)) { memset (DP, 0, sizeof (DP)); int p = ceil (log2 (1.0 * N)) + 1; LL ans = 1; for (int i = p; I >= 2; i--) { Dp[i] = POW (1.0 * N, 1.0/i)-1 + exps; for (int j = 2 * i; J <= p; j + = i) { dp[i]-= Dp[j]; } Ans + = Dp[i]; } printf ("%i64d\n", ans); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Tolerance theorem hdu2204 Eddy ' s hobby