Yada Numberproblem Description:
Every positive integer can is expressed by multiplication of prime integers. Duoxida says an integer was a yada number if the total amount of 2,3,5,7,11,13 in it prime factors is even.
For instance, 18=2 * 3 * 3 are not a yada number since the sum of amount of 2, 3 are 3, an odd number; While-2 * 5 * is a yada number since the sum of amount of 2, 5 is 2, a even number that satifies the definition O f yada number.
Now, Duoxida wonders how many yada number is among all integers in [1,n].
Input
The first line contains an integer T (no more than) which indicating the number of test cases. In the following T lines containing a integer n. ()
Output
For each case, output the answer on one single line.
Sample Input
2
18
21st
Sample Output
9
11
Test instructions: Q 1[,n] interval, how many numbers, its 2,3,5,7,11,13 of the number of these factors are even
Idea: Preprocess all x to meet the 2,3,5,7,11,3 of X only, and the number is even. The number of x 13000+;
For a number n, the enumeration of all x, for a x,f (n/x) to find out [1,n/x] does not contain the number of 2,3,5,7,11,13 as a factor, this is the classic repulsion problem. Sum all f (n/x)
I use the priority queue and map to process X; ll timeout; there's a place that explodes int and handles the next
1#include <bits/stdc++.h>2 using namespacestd;3 #definell Long Long4 #defineMoD 10000000075 #defineINF 9999999996 #definePi 4*atan (1)7 //#pragma COMMENT (linker, "/stack:102400000,102400000")8 intp[Ten]={2,3,5,7, One, -};9 intnum[20010],ji,ans;Ten struct is One { A intx; - intStep; - BOOL operator< (Const isAConst the { - returnX>a.x; - } - }; +priority_queue< is>Q; -map<int,int>m; + intgcdintXinty) A { at returny==0? X:GCD (y,x%y); - } - voidInit () - { -li{0; - isA; ina.x=1; -m[1]=1; toa.step=0; + Q.push (a); - while(!q.empty ()) the { * isb=q.top (); $ if(b.x>1e9)Panax Notoginseng Break; - Q.pop (); the if(b.step%2==0) +num[ji++]=b.x; A for(intI=0;i<6; i++) the { + isC; -ll gg= (LL) b.x*P[i]; $ if(GG>1E9) Break; $c.step=b.step+1; -C.x= (int) GG; - if(c.x<=1e9&&m[c.x]==0) theQ.push (c), m[c.x]=1; - }Wuyi } the } - voidDfsintLcmintPosintStepintx) Wu { - if(lcm>x) About return; $ if(pos==6) - { - if(step==0) - return; A if(step&1) +ans+=x/LCM; the Else -ans-=x/LCM; $ return; the } theDFS (lcm,pos+1, step,x); theDFS (LCM/GCD (P[POS],LCM) *p[pos],pos+1, step+1, x); the } - intMain () in { the intx,y,z,i,t; the init (); About intT; thescanf"%d",&T); the while(t--) the { +scanf"%d",&x); - intans=0; the for(i=0; i<ji&&num[i]<=x;i++)Bayi { theans=0; theDfs1,0,0, x/num[i]); -ans+= (x/num[i]-ans); - } theprintf"%d\n", Ans); the } the return 0; the}
Xtu 1242 Yada Number tolerance principle