Codeforces 385C Bear and Prime Numbers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.