Y. The Great Prime
Problem linkhttps://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/Y
Score: 1
CPU: 1s
Memory: 512MB
CPU: 1s
Memory: 512MB
Given
Input
First you will be given an positive integer
Output
For each test case first you have to print “
N
you have to find out whether N
is a prime number or not. If you don’t know what a prime is, then read about Prime here.Input
First you will be given an positive integer
T (1< T < 100)
, the number of test case. For each test case you will be given N( 0 < N < 1000 )
in different lines.Output
For each test case first you have to print “
Case X:
”, where X
is the case number. Then if N
is prime then print “YES
” and “NO
” if not prime.Sample
Input | Output |
---|---|
4 5 9 19 25 | Case 1: YES Case 2: NO Case 3: YES Case 4: NO |
Solution
#include<math.h> #include<stdio.h> int main() { int f,h,s,e,i,b; scanf("%d",&s); for(f=1;f<=s;f++) { scanf("%d",&h); e=sqrt(h); b=0; for(i=2;i<=e;i++) { if(h%i==0) { printf("Case %d: NO\n",f); b++; break; } } if(b==0) { printf("Case %d: YES\n",f); } } return 0; }
No comments:
Post a Comment