Description
Small X likes to count since childhood. But strangely enough, he hated the total square number. He thinks these
The numbers look very unpleasant. As a result, he also hates the number of positive integer multiples of the total squared number. However
This does not affect his love for other numbers at all.
This day is small x's birthday, small W wants to send a number to him as a birthday present. Of course he can't send a
A little x nasty number. He listed all the small x not annoying number, and then selected the number of K sent to the
Small x. Little X was happy to accept it.
But now little W can't remember which number is given to the small x. Can you help him?
Hint
1≤ki≤10^9,t≤50 for 100% of data
Solution
Test instructions: x, make ∑| Μ[i] | ==k (1<= i <=n)
First, according to the definition of the μ function, the exponent of the existence factor in all the mass factors of a natural number I is greater than 2,μ[I]=0
To convert the description of the condition, if I contains a full square factor, μ[I]=0
We define F (x) to be less than or equal to x μ[i]! = number of I of 0
Consider subtracting the number of μ[I] ==0 from X
We enumerate the number of factor I, which is less than or equal to x in number of I squared, obviously x/i^2
According to the allowance, the front multiply a coefficient μ[i]
Then ask for a and, two-point answer, the complexity is approximately o (n) preprocessing + O (√n * log n) Single access
1#include <map>2#include <cmath>3#include <ctime>4#include <queue>5#include <stack>6#include <cstdio>7#include <climits>8#include <iomanip>9#include <cstring>Ten#include <cstdlib> One#include <iostream> A#include <algorithm> - - #defineMAXP 50000 the #defineSet (a B) memset (A, (b), sizeof (a)) - #defineFR (i,a,b) for (ll i= (a), _end_= (b); i<=_end_;i++) - #defineRF (I,b,a) for (ll i= (a), _end_= (b); i>=_end_;i--) - #defineFe (I,A,B) for (int i=first[(b)],_end_= (a); i!=_end_;i=s[i].next) + #defineFEC (I,A,B) for (int &i=cur[(b)],_end_= (a); i!=_end_;i=s[i].next) - + using namespacestd; A attypedefLong Longll; - - Constll up=2e9; - - -ll prime[maxp],pri[maxp],miu[maxp],tot=0; in ll Ans,k; - intT; to + voidRead () - { the #ifndef Online_judge *Freopen ("2440.in","R", stdin); $Freopen ("2440.out","W", stdout);Panax Notoginseng #endif -CIN >>T; the } + A voidWrite () the {} + - voidprint () $ { $cout << ans <<Endl; - } - the void Get() - {Wuyimiu[1]=1; theFr (I,2, MAXP) { - if(!prime[i]) pri[++tot]=i,miu[i]=-1; Wu intj=1; - while(J<=tot && pri[j]*i<=Maxp) { Aboutprime[pri[j]*i]=1; $ if(i%pri[j]==0 ){ -miu[pri[i]*j]=0; - Break; - } Amiu[i*pri[j]]=-Miu[i]; +J + +; the } - } $ } the the ll Calc (ll x) the { thell res=0; -Fr (I,1, sqrt (x)) inres+= (x/(i*i)) *Miu[i]; the returnRes; the } About the voidWork () the { the Get(); + while(t-- ){ -CIN >>K; thell l=1, r=Up,mid;Bayi while(l<=R) { theMid= (l+r) >>1; the if(Calc (mid) >=k) ans=mid,r=mid-1; - ElseL=mid+1; - } the print (); the } the } the - intMain () the { the read (); the Work ();94 write (); the return 0; the}
Bzoj 2440: [Zhongshan 2011] Total Square number