标签:codeforces 数论
找出在[l,r]中的素数t,满足
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#define MAX 300000007
using namespace std;
//bool mark[MAX>>1];
vector<bool> mark ( MAX>>1 , 0 );
int l,r;
void init ( )
{
//memset ( mark , true , sizeof ( mark ) );
for ( int i = 3; i*i < MAX ;i += 2 )
{
if ( mark[i>>1] ) continue;
for ( int j = i*i ; j < MAX ; j += (i<<1) )
mark[j>>1] = 1;
}
}
int main ( )
{
init ( );
while ( ~scanf ( "%d%d" , &l , &r ) )
{
int ans = 0;
if ( l <= 2 && r >= 2) ans++;
int ll = max ( (int)ceil((l-1)*1.0/4.0 ) , 1 );
for ( int i = (ll<<2)+1 ; i <= r ; i += 4 )
if ( !mark[i>>1] )
ans++;
printf ( "%d\n" , ans );
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
codeforces 113C C. Double Happiness(数论+暴力)
标签:codeforces 数论
原文地址:http://blog.csdn.net/qq_24451605/article/details/48270501