Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include<iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5. int N = 100000;
  6. bool sito[100000];
  7.  
  8. int silnia(int n)
  9. {
  10.     int wynik = 1;
  11.     if(n<2)
  12.     {
  13.         return 1;
  14.     }
  15.  
  16.     for(int i=2; i<=n; i++)
  17.     {
  18.         wynik=wynik*i;
  19.     }
  20.  
  21.     return wynik;
  22. }
  23.  
  24.  
  25. bool czyPierwsze(int n)
  26. {
  27.     if(n<2)
  28.     {
  29.         return false;
  30.     }
  31.  
  32.     for(int i=2; i<sqrt(n)+1; i++)
  33.     {
  34.         if(n%i==0)
  35.         {
  36.             return false;
  37.         }
  38.     }
  39.  
  40.     return true;
  41. }
  42.  
  43. void przesiew()
  44. {
  45.     for(int i=2; i<N; i++)
  46.     {
  47.         if(sito[i]==true)
  48.         {
  49.             for(int j=i+i; j<N; j+=i)
  50.             {
  51.                 sito[j]= false;
  52.             }
  53.         }
  54.     }
  55. }
  56.  
  57.  
  58. void wyczyscSito()
  59. {
  60.     for(int i=2; i<N; i++)
  61.     {
  62.         sito[i] = true;
  63.     }
  64. }
  65.  
  66. void wypiszSito()
  67. {
  68.     for(int i=0;i<N; i++)
  69.     {
  70.         cout<<sito[i]<<" ,";
  71.     }
  72. }
  73.  
  74. int main()
  75. {
  76.     // int a;
  77.     // cin>>a;
  78.     wyczyscSito();
  79.     przesiew();
  80.  
  81.     for(int i=0;i<N;i++)
  82.     {
  83.         if(sito[i]==true)
  84.         {
  85.             cout<<i<<" ,";
  86.         }
  87.        
  88.     }
  89.  
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement