fork download
  1. /*
  2.   Author: NgThi Thao Duyen
  3.   Link submit:
  4. */
  5.  
  6. #include<bits/stdc++.h>
  7. using namespace std;
  8. #define ll long long
  9. #define task "LEAD"
  10. #define fi first
  11. #define se second
  12. #define pii pair<int,int>
  13. #define pb push_back
  14. #define dou double
  15. #define el '\n'
  16. #define ull unsigned long long
  17. #define pll pair<ll,ll>
  18. const ll maxN = 1e6;
  19. const ll maxM = 1e3;
  20. const ll LIM = 1e9;
  21. const ll oo = 1e18;
  22. const ll mod = (ll)1e9+7;
  23. const ll LOG = 23;
  24.  
  25. int num;
  26.  
  27. int check_prime(int num)
  28. {
  29. if(num < 2) return 0; //không là số nguyên tố => trả về 0
  30. //Ngược lại thì kiểm tra từ 2 -> sqrt(num)
  31. for(int i=2; i*i<=num; i++)
  32. {
  33. if(num % i == 0) return 0;
  34. //nếu num chia hết cho một số i (khác bằng num)
  35. //=>vi phạm điều kiện chỉ chia hết cho 1 và chính nó => trả về 0
  36.  
  37. }
  38. //Nếu đã kiểm tra một lượt mà thoả mãn thì return về 1
  39. return 1;
  40. }
  41.  
  42.  
  43. int main()
  44. {
  45. ios_base::sync_with_stdio(0); cin.tie(0);
  46. if(fopen(task".inp","r"))
  47. {
  48. freopen(task".inp","r",stdin);
  49. freopen(task".out","w",stdout);
  50. }
  51. cin >> num;
  52. if(check_prime(num)) cout<<"YES";
  53. else cout<<"NO";
  54. return 0;
  55. }
  56.  
  57.  
  58.  
  59.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
NO