素数鰓选法
好孩子
posted @ 2011年8月19日 12:07
in 数论
, 623 阅读
#include<stdio.h> |
#include<stdlib.h> |
#include<math.h> |
#include<string.h> |
#include<time.h> |
|
int T; |
|
bool Is( int x ) |
{ |
int sum=0; |
for ( int i=1 ;i< x;++i ) |
if ( !(x%i) ) |
sum+=i; |
if ( sum==x ) |
return true ; |
else |
return false ; |
} |
|
int main() |
{ |
scanf ( "%d" ,&T ); |
while (T--) |
{ |
int a,b,cnt=0; |
scanf ( "%d%d" ,&a,&b ); |
if ( a>b ) |
a^=b^=a^=b; |
for ( int i=a ;i<=b;++i ) |
if ( Is( i ) ) |
cnt ++; |
printf ( "%d\n" ,cnt ); |
} |
|
return 0; |
} |