Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <Windows.h>
- using namespace std;
- int main()
- {
- DWORD tc=GetTickCount();
- int prim, n, i, j=2;
- unsigned long long sum=5;
- int primek[150000];
- primek[0]=2;
- primek[1]=3;
- for(int n=5; n<2000000; n+=2)
- {
- prim=1;
- int n_sqrt=sqrt(n);
- for(int i=1; primek[i]<=n_sqrt; ++i)
- {
- if(n%primek[i]==0)
- {
- prim=0;
- break;
- }
- }
- if(prim)
- {
- sum+=n;
- primek[j++]=n;
- }
- }
- cout << "All primes:\t" << j << endl;
- cout << "Sum:\t\t" << sum << endl;
- cout << "Time elapsed:\t" << (int)((GetTickCount()-tc)/1000)
- <<'.'<<((GetTickCount()-tc)-((GetTickCount()-tc)/1000)*1000);
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement