Advertisement
MichalWalczak

Zad 22

Mar 30th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5. long long int a;
  6.  
  7. long long int NASTEPNA_PIERWSZA(long long int liczba){
  8.     bool b=true;
  9.     if(liczba==1){
  10.         return 2;
  11.     }
  12.     else if(liczba==2){
  13.         return 3;
  14.     }
  15.     else{
  16.     liczba++;
  17.         for(long long int i=2; i<=sqrt(liczba); i++){
  18.             if(liczba%i==0){
  19.                 b=!b;
  20.                 liczba++;
  21.                 i=1;
  22.                 if(b==false){
  23.                     b=!b;
  24.                 }
  25.             }
  26.  
  27.     }
  28.      if(b==true){
  29.         return liczba;
  30.      }
  31.  
  32. }
  33. }
  34. int main()
  35. {
  36.     cout << "Podaj liczbe, aby znalezc liczbe pierwsza wieksza od niej" << endl;
  37.     cin>>a;
  38.     if(a<0){
  39.     cout<<"Liczba ma byc wieksza od zera";
  40.     }
  41.     else {
  42.         cout<<NASTEPNA_PIERWSZA(a);
  43.     }
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement