Advertisement
thesonpb

số nguyên tố

Mar 30th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. bool isPrime(int n){
  4.     if(n<=1) return false;
  5.     for(int i=2; i<=n/2; i++){
  6.         if(n%i==0) return false;
  7.     }
  8.     return true;
  9. }
  10. int main(){
  11.     int n;
  12.     cin >> n;
  13.     for(int i=2; i<=n; i++){
  14.         if(isPrime(i)) cout<<i<<endl;
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement