Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2204
Solution Report: Input n to obtain the number of results in the range of [1, N], which can be expressed as m ^ K.
I will not elaborate on it. At the beginning, I ignored the multiplication of the product of the three prime numbers.
1 # include <cstdio> 2 # include <cstring> 3 # include <iostream> 4 # include <algorithm> 5 # include <cmath> 6 using namespace STD; 7 typedef long int; 8 int prim [70]; 9 10 int dabiao () 11 {12 INT f = 0; 13 for (INT I = 2; I <60; ++ I) 14 {15 int flag = 1; 16 17 for (Int J = 2; j <I; ++ J) 18 if (I % J = 0) 19 {20 flag = 0; 21 break; 22} 23 if (FLAG) prim [f ++] = I; 24} 25 return F; 26} 27 28 int calc (int A, int B, int N) 29 {30 int S = 1; 31 while (B --) 32 {33 If (INT) (N/A) <= s) return 0; 34 S * =; 35} 36 return 1; 37} 38 int main () 39 {40 int N; 41 int num = dabiao (); 42 while (scanf ("% i64d ", & N )! = EOF) 43 {44 int tot = 1; 45 for (INT I = 0; I <num; ++ I) 46 {47 int temp = (INT) pow (double) n, 1.0/prim [I]); 48 if (temp = 1) break; // if less than 1 after the start, exit 49 tot + = temp-1; // minus 1 because 150} 51 for (INT I = 0; I <num; ++ I) is counted every time) 52 for (Int J = I + 1; j <num; ++ J) 53 {54 int temp = POW (double) n, 1.0/(prim [I] * prim [J]); 55 if (temp = 1) break; 56 tot-= temp-1; 57} 58 for (INT I = 0; I <num; ++ I) 59 for (Int J = I + 1; j <num; ++ J) 60 for (int K = J + 1; k <num; ++ K) 61 {62 int temp = POW (double) n, 1.0/(prim [I] * prim [J] * prim [k]); 63 If (temp = 1) break; 64 tot + = temp-1; 65} 66 printf ("% i64d \ n", TOT); 67} 68 return 0; 69}
View code
HDU 2204 Eddy's hobby)