fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5.  
  6. int isPrime(int n){
  7.  
  8. if(n<=1){
  9. return 0;
  10. }
  11.  
  12. int byTwo=n/2;
  13. int i=0;
  14. int result=1;
  15.  
  16.  
  17.  
  18. for(i=2;i<=byTwo;i++){
  19.  
  20. if((n%i)==0){
  21. result=0; // it not prime.
  22. break;
  23. }
  24.  
  25. }
  26.  
  27. if(result==0){
  28. return 0;
  29. }
  30.  
  31. return 1;
  32.  
  33. }
  34.  
  35. int main() {
  36.  
  37. int count=0,i=0,j=0;
  38. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  39. scanf("%d",&count);
  40. int arr[count];
  41. // int arr2[count];
  42. int byTwo=0;
  43. int n=0;
  44. int result=1;
  45.  
  46. for(i=0;i<count;i++){
  47.  
  48. scanf("%d",&arr[i]);
  49.  
  50. }
  51.  
  52.  
  53. for(j=0;j<count;j++){
  54.  
  55.  
  56. if(isPrime(arr[j])==1){
  57. printf("YES\n");
  58.  
  59. }
  60. else
  61. {
  62. printf("NO\n");
  63. }
  64.  
  65. }
  66.  
  67.  
  68. return 0;
  69. }
  70.  
Success #stdin #stdout 0s 2012KB
stdin
5
2
3
4
5
6
stdout
YES
YES
NO
YES
NO