Title Link: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=23362
Test instructions: Defines a number that contains a squared factor as a complete square number (the square number factor does not contain 1). The number of k non-complete squares is obtained.
Idea: We first find the number of non-complete squares of [1, N], and then use the binary to look for n that is exactly equal to K (note that n may be more than one, the leftmost). The key is, how to find the former, we can use the principle of tolerance, with n-[1, N] The number of complete square number, to [1, N] The number of complete square number, with the capacity to find the front coefficient is Möbius function, directly with Möbius inversion can be, the result is Sigma (mu[i]* (n/(i*i) ))。
Code
1#include <cstdio>2#include <cstring>3 using namespacestd;4 5typedefLong LongLL;6 7 ConstLL INF = 2e10 +7;8 Const intMAXN =100005;9 Ten BOOLCHECK[MAXN]; One intPRIMES[MAXN]; A intMU[MAXN]; - LL K; - the voidMoblus () - { -memset (check,false,sizeof(check)); -mu[1] =1; + intCNT =0; - for(inti =2; i < MAXN; ++i) { + if(!Check[i]) { Aprimes[cnt++] =i; atMu[i] =-1; - } - for(intj =0; J < CNT; ++j) { - if(i * primes[j] > MAXN) Break; -Check[i * Primes[j]] =true; - if(i% primes[j] = =0) { inMu[i * Primes[j]] =0; - Break; to}Else { +Mu[i * Primes[j]] =-Mu[i]; - } the } * } $ }Panax Notoginseng - ll Cal (ll N) the { +LL ret =N; A for(LL i =2; I * I <= N; ++i) { theRET + = mu[i] * (N/(i *i)); + } - returnret; $ } $ - intMain () - { the Moblus (); - intncase;Wuyiscanf"%d", &ncase); the while(ncase--) { -scanf"%lld", &k); WuLL LHS =1L; -LL RHS =INF; About LL mid; $ while(LHS <RHS) { -MID = (RHS + LHS)/2; -LL tmp =Cal (mid); - if(TMP < k) LHS = mid +1; A ElseRHS =mid; + } theprintf"%lld\n", LHS); - } $ return 0; the}
Bzoj 2440 Full Square (Möbius inversion + binary search)