Не сте регистриран! Регистрирайте се БЕЗПЛАТНО, за да използвате услугите на сайта!

 B&W's Prime Searching method
Автор  magadanski_uchen (22.06.2006 23:19) съобщение до автора
Погледнат  2062 пъти добави към любими
Оценка добави коментар
Гласове  8 изпрати на приятел
Коментари  (0) абонирай се за C-Cplusplus
     
magadanski_uchen
     
 

CODE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 
Name: B&W's Prime Searching method (Compile with Borland C++ Builder)
 
Copyright: Black&White - june,2006 - freeware, open source
 
Author: eng. Chris Popoff (also known as Black`n`White)
 
Date: 22/06/06 19:03 [i]Not final version - I'm waiting for advices[/i]
 
Description: Search Engine for prime numbers (max to 64-bit integers)
              
To stop the searching engine press 'Ctrl+S' to see the
              
last prime found, then 'Ctrs+C' to stop. Next time, when
              
you start the searching engine change the value at the
              
position marked with ( *** ) from the source code to
               the
last prime, you have found. NOTE: The number must not
              
be even. Look forward for next releases of this program.
              
At last this project will be transformed to a
               benchmarking software
.
*/

#include <cstdlib>
#include <iostream>
#include <ctime>
#include <cmath>
#define START 3 // *** Start searching from n ( !!! not even )
#define FIND 100000 // *** Stop after finding n primes

using namespace std;

int pd = 2;
bool test(long long p);

int main()
{  

   
register long long p;

   
time_t s,e;
   
s = time(NULL);
   
cout << "Primes: " << endl;
   
cout << "1" << endl;
   
cout << "2" << endl;
   
for(p = START; pd < FIND; p+=2)
         
if(test(p))
          {
                    
cout << p << "ttt" << ++pd << endl;
         
}

   
e = time(NULL);
   
cout << endl << pd << " primes found" << endl;
   
cout << "for " << difftime(e,s) << " seconds" << endl;
   
system("PAUSE");
   
return EXIT_SUCCESS;
}

bool test(register long long p)
{
    
register long long c;
    
bool pc = true;

    
for(c = 3; c < sqrtl(p+1); c++)
     {
          
if(!(p % c))
           {
                 
pc = false;
                 
break;
          
}
     }
    
    
return pc;
}



Ключови думи: C++ search method метод




 За автора: magadanski_uchen  
Никой не може да знае всичко, но нека си помогнем един на друг и споделим знанията си с останалите. Моля помагайте на мен повечко, защото определено се нуждая :Р.
   
 1 посетител чете този скрипт (0 потребители и 1 гост)  
Активни потребители: ---
   
  

Еmail  
 

 

 
  • Интересно от Софтуер
 
  • Интересно от myLINKS
 
 
 
 



IT-PLACE.NET © 2004 - 2008