Test instructions
Find the number of integers between L and U x satisfies the form such as X=PK, where P is prime, k>1
Analysis:
First, sift out the primes in 1e6, enumerate each prime number to find out 1e12 of all the numbers that satisfy the condition, and then sort.
For L and U, the two points find the subscript of the maximum number less than U and L, and the difference is the answer.
1#include <cstdio>2#include <cmath>3#include <algorithm>4 5typedefLong LongLL;6 7 Const intMAXN =1000000;8 Const intMAXP =80000;9 Ten BOOLVIS[MAXN +Ten]; One intPRIME[MAXP], CNTP =0; ALL A[MAXN], cnt =1; - - voidInit () the { - intm = +; - for(inti =2; I <= m; ++i)if(!Vis[i]) - for(intj = i * I; J <= Maxn; J + = i) vis[j] =true; + for(inti =2; I <= MAXN; ++i)if(!vis[i]) prime[cntp++] =i; - + for(inti =0; i < CNTP; ++i) A { atll temp = (LL) prime[i] *Prime[i]; - while(Temp <=1000000000000LL) - { -a[cnt++] =temp; -Temp *=Prime[i]; - } in } -Std::sort (A, A +CNT); to } + - intBinary_search (LL N) the { *LL L =0, R =CNT; $ while(L <R)Panax Notoginseng { -LL mid = ((L + R +1) >>1); the if(A[mid] <= N) L =mid; + ElseR = mid-1; A } the returnL; + } - $ intMain () $ { - Init (); - intT; thescanf"%d", &T); - while(t--)Wuyi { the LL hehe, haha; -scanf"%lld%lld", &hehe, &haha); Wu intt = Binary_search (hehe), k =binary_search (haha); - intAns = k-T; About if(A[t] = = hehe) ans++; $printf"%d\n", ans); - } - - return 0; A}
code June
UVa 10539 (Sieve primes, two-point search) almost prime Numbers