#include<iostream>
#include<cmath>
using namespace std;
int p[10002];
int ans[2002];
int len;
__int64 ModExp( __int64 a , __int64 b , __int64 n )
{
__int64 m = 1;
while( b )
{
if( b & 1 )
{ m = ( m % n ) * ( a % n ) % n; }
b >>= 1;
a = ( a % n ) * ( a % n ) % n;
}
return m;
}
bool miller_rabbin(__int64 n)
{
__int64 i , a;
for( i = 0 ; i < 50 ; i++ )
{
a = rand() % ( n - 2 ) + 2;
if( ModExp( a , n - 1 , n ) != 1 )
{ return false; }
}
return true;
}
void Prime()
{
__int64 i;
p[0] = 2;
for( i = 3 ; i <= 100000 ; i = i + 1 )
{
if( miller_rabbin( i ) )
{ p[len++] = i; }
}
}
int main()
{
int i , j;
int n , k;
int sum;
len = 0;
k = 0;
Prime();
memset( ans , 0 , sizeof( ans ) );
for( j = 0 ; j < len - 1 ; ++j )
{
if( p[j + 1] - p[j] == 2 )
{ ans[k++] = p[j + 1]; }
}
while( scanf( "%d" , &n ) )
{
if( n < 0 )
{ break; }
sum = 0;
for( i = 0 ; i < k ; ++i )
{ if( ans[i] > n ) break; }
printf( "%d/n" , i );
}
return 0;
}
数论 MillerRabin hdu 3792
最新推荐文章于 2018-10-29 19:28:07 发布