The goal of this problem is simple, to determine whether a given positive integer is prime or not.
Input format:
The input gives a positive integer N (<=10) on the first line, followed by N lines, each of which gives a positive integer less than 2 31 to be judged.
Output format:
For each positive integer that needs to be judged, if it is a prime number, output "Yes" in one line, otherwise output "No".
Input sample:2 11 111Sample output:
Yes No
Code:
#include<stdio.h> #include<math.h> intmain() { int i,j,n,m,k,t,l; scanf("%d",&n); for(l=0;l<n;l++) { scanf("%d",&m); if(m==1) { printf("No\n"); continue; } for(i=2;i<=sqrt(m);i++) { if(m%i==0) break; } if(i>sqrt(m)) { printf("Yes\n"); } else { printf("No\n"); } } return 0; }