Esempio n. 1
0
longint& 
Sievelng<longint>::first_prime()
{
  eratosthene();
  cursor = -1;
  return next_prime();
}
Esempio n. 2
0
longint&
Sievelng<longint>::last_prime()
{
  eratosthene();
  cursor = 1+index(B);
  return previous_prime();
}
Esempio n. 3
0
longint&
Sievelng<longint>::previous_prime()
{
  for (;;) {
    if (cursor < 0) {
      if (A <= 1) {
	resimage = 1;
	return resimage;
      }
      else
	{
	  backward();
	  eratosthene();
	  cursor = Btable::bsize()-1;
	}
    }
    else cursor--;

    while (cursor >= 0)
      {
	if (is_set_bit(cursor))
	  {
	    return image(cursor);
	  }
	cursor--;
      }
  } 
}
Esempio n. 4
0
LongGmp&
Sievelgmp::last_prime()
{
  eratosthene();
  cursor = 1+index(B);
  return previous_prime();
}
Esempio n. 5
0
LongGmp& 
Sievelgmp::first_prime()
{
  eratosthene();
  cursor = -1;
  return next_prime();
}
Esempio n. 6
0
/**
 * Run the process
 */
void init(){
    
    // Retrieve the limit
    int limit = getValue();
    
    int array[limit];
    int i = 0;
    
    // Fills the array with all value until limit
    for(i=0; i <= limit; ++i){
        array[i] = i;
    }
    
    // Run the calculation
    eratosthene(array, limit);
    
    printf("\n");
    
    // Display the result
    display(array, limit);
}
Esempio n. 7
0
longint& 
Sievelng<longint>::next_prime()
{
  for (;;) {
    //    cerr << "Cursor = max_bit_index" << endl;
    if (cursor >= max_bit_index) {
      forward();
      eratosthene();
      cursor = 0;
    }
    else cursor++;

    while (cursor <= max_bit_index)
      {
	if (is_set_bit(cursor))
	  {
	    //    cerr << "Ok cursor = " << cursor << "  image(cursor) = "
	    //	 << image(cursor) << endl;
	    return image(cursor);
	  }
	else cursor++;
      }
  } 
}