Test instructions: Give you a series, and M inquiry, to find the number of multiples of all prime numbers in the array of L-r.
Problem-solving ideas: deformation sieve method. Attention to detail
Problem Solving Code:
1 //File name:385c.cpp2 //Author:darkdream3 //Created time:2015 March 07 Saturday 18:24 53 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> - #defineLL Long Long - using namespacestd; - Const intMAXN =1000000*Ten+ +; - intANS[MAXN]; - intHS[MAXN]; in intAHS[MAXN]; - intN; to voidSolve () + { - //int tmp = sqrt (MAXN); the for(inti =2; i < Maxn;i + +) * { $ if(Hs[i] = =0)Panax Notoginseng { - for(intj = i; j < maxn;j + =i) the { + AAns[i] + =Ahs[j]; theHS[J] =1; + } - } $ } $ for(inti =2; I <= Maxn;i + +) - { -Ans[i] + = ans[i-1]; the } - }Wuyi intMain () { thememset (ans,0,sizeof(ans)); -memset (HS,0,sizeof(HS)); Wumemset (AHS,0,sizeof(AHS)); -scanf"%d",&n); About int_max =0; $ for(inti =1; I <= N;i + +) - { - inttmp; -scanf"%d",&tmp); AAHS[TMP] + +; +_max =Max (Tmp,_max); the } - solve (); $ intm; thescanf"%d",&m); the for(inti =1; I <= M;i + +) the { the intL, R; -scanf"%d%d",&l,&R); in if(L >_max) the { theprintf"0\n"); About Continue; the } theR =min (r,_max); theprintf"%d\n", Ans[r]-ans[l-1]); + } - return 0; the}View Code
Codeforces 385C Bear and Prime Numbers