A% B problem

Source: Internet
Author: User

P1865 A% B problem
    • Difficulty popularization/improvement-

Title background title is to attract you to come in the fact that the problem is still very water topic description

Number of interval mass

Input output Format input format:

Row of two integer queries N, Range m

The next n rows, two integers per line, l,r indicate the interval

Output format:

For each query output number T, such as L or r∉[1,m] output Crossing the line

Input and Output Sample input example # #:
2 51 32 6
Sample # # of output:
2Crossing the line
Description

"Data scope and conventions"

For 20% of data 1<=n<=10 1<=m<=10

For 100% data 1<=n<=1000 1<=m<=1000000-10^9<=l<=r<=10^9 1<=t<=1000000

#include <iostream>#include<cstdio>#include<cstring>using namespacestd;Long Longn,m,l,r,f[1000001],s[1000001],sum;intMain () {CIN>>n>>m; Memset (F,1,sizeof(f)); f[1]=0;  for(intI=2; i<=m; i++)//Prime Sieve    {        if(F[i]) { for(intJ=i+i; j<=m; j+=i) f[j]=0; }        }     for(intI=1; i<=m; i++)//Number of characters between 1 and I    {        if(F[i]) sum++; S[i]=sum; }     for(intI=1; i<=n; i++)//Output Processing{cin>>l>>R; if(r>m| | r<1|| l<1|| L>m) cout<<"Crossing the line"<<Endl; Else        {            if(F[l]) cout<<s[r]-s[l]+1<<Endl; Elsecout<<s[r]-s[l]<<Endl; }    }    return 0;}

A% B problem

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.