Advertisement
anhkiet2507

LIET KE SO NGUYEN TO - 1

Aug 26th, 2021
2,340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. long long SNT(long long n){
  4.     if(n<2){
  5.         return 0;
  6.     }
  7.     int i;
  8.     for(i = 2; i<=sqrt(n); i++){
  9.         if(n%i==0){
  10.             return 0;
  11.         }
  12.     }
  13.     return 1;
  14. }
  15. using namespace std;
  16. int main() {
  17.         long long a,b,i;
  18.         cin >> a;
  19.         cin >> b;
  20.         if(a<=b){
  21.             for(i = a; i<=b; i++){
  22.                 if(SNT(i)==1){
  23.                     cout << i << " ";
  24.                 }
  25.             }
  26.         }else{
  27.             for(i = b; i<=a; i++){
  28.                 if(SNT(i)==1){
  29.                     cout << i << " ";
  30.                 }
  31.             }          
  32.         }
  33.         cout << endl;
  34.     return 0;
  35. }
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement