Welcome

>>>Welcome to my "CODE BAZAR"
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others

Update ✔✔✔ Upcoming programming book (.pdf) "Programming Contest (data structures and algorithms) by Md. Mahbub Hasan & "Graph Algorithms" by Safayat Asraf "****** Date: 20 March, 2019****Hazrat Ali****

Monday 31 October 2016


Y. The Great Prime
Problem link
https://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/Y


Score: 1

CPU: 1s
Memory: 512MB

Given 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

InputOutput
4 5 9 19 25Case 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