Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <math.h>
- using namespace std;
- int prim(int szam)
- {
- if(szam<2) return 0;
- else if(szam==2) return 1;
- if(szam%2==0) return 0;
- double szam_n=sqrt(szam);
- for(int i=3; i<=szam_n; i+=2)
- {
- if(szam%i==0)
- return 0;
- }
- return 1;
- }
- int main(int argc, char** argv)
- {
- DWORD tc=GetTickCount();
- int max=2000000;
- unsigned long int prims_count=0;
- unsigned long long osszeg=0;
- for(int i=2; i<=max; i++)
- {
- if(prim(i))
- {
- osszeg+=i;
- prims_count++;
- }
- }
- cout << "All primes:\t" << prims_count << endl;
- cout << "Sum:\t\t" << osszeg << 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