Advertisement
semsem_elazazy

D. Prime Function

Feb 18th, 2022
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. #define ll long long
  4. using namespace std;
  5.  
  6. void check_prime(int n)
  7. {
  8.     bool ch =0 ;
  9.     if (n==2) cout<<"YES"<<"\n";
  10.     else
  11.     {
  12.     for(int i = 2 ;i<n ;i++)
  13.     {
  14.      if (n%i ==0  )
  15.      {
  16.           ch =1;
  17.          break;
  18.      }
  19.     }
  20.     if (ch == 0 ) cout<<"YES"<<"\n";
  21.     else          cout<<"NO"<<"\n";
  22.     }
  23. }
  24.  
  25. int main() {
  26.    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  27.  
  28. int t;
  29. cin>>t;
  30. while(t--)
  31. {
  32.     int n;
  33.     cin>>n;
  34.     check_prime(n);
  35. }
  36.  
  37.     return 0;
  38. }
  39.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement