Knowee
Questions
Features
Study Tools

An integer value N is passed as the input. The program must print YES if N is prime number. Else the program must print NO.Input Format:The first line denotes the value of N.Output Format:YES or NO based on if N is a prime number or not. (The OUTPUT is CASE SENSITIVE).Boundary Conditions:2 <= N <= 9999999Example Input/Output 1:Input:19Output:YESExample Input/Output 2:Input:189210Output:NO

Question

An integer value N is passed as the input. The program must print YES if N is prime number. Else the program must print NO.Input Format:The first line denotes the value of N.Output Format:YES or NO based on if N is a prime number or not. (The OUTPUT is CASE SENSITIVE).Boundary Conditions:2 <= N <= 9999999Example Input/Output 1:Input:19Output:YESExample Input/Output 2:Input:189210Output:NO

🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a Python solution for the problem:

def is_prime(n):
    if n <= 1 or (n % 2 == 0 and n > 2): 
        return "NO"
    for i in range(3, int(n**0.5) + 1, 2):
        if n % i == 0:
            return "NO"
    return "YES"

N = int(input())
print(is_prime(N))

This program works by defining a function is_prime(n) that checks if a number n is prime.

First, it checks if n is less than or equal to 1 or if it's an even number greater than 2. If either of these conditions are true, it returns "NO" because n is not a prime number.

Then, it checks if n is divisible by any odd number up to the square root of n. If n is divisible by any of these numbers, it returns "NO" because n is not a prime number.

If n passes both of these checks, it returns "YES" because n is a prime number.

Finally, the program reads an integer N from the input, calls is_prime(N), and prints the result.

This problem has been solved

Similar Questions

Problem statementSend feedbackYou are given a positive integer ‘N’. Your task is to print all prime numbers less than or equal to N.Note: A prime number is a natural number that is divisible only by 1 and itself. Example - 2, 3, 17, etc.You can assume that the value of N will always be greater than 1. So, the answer will always exist.Detailed explanation ( Input/output format, Notes, Images )Constraints:2 <= N <= 10^7Where ‘N’ is the given positive integer.Time Limit: 1secSample Input 1 :7Sample Output 1 :2 3 5 7Sample Output 1 Explanation:For the given input, all prime numbers from 2 to 7 are 2, 3, 5 and 7.Sample Input 2 :30Sample Output 2 :2 3 5 7 11 13 17 19 23 29

Problem Statement:Find whether the given number is prime or not.Input Format:Accept an integer as inputOutput Format:Print the output as "Prime Number" or "Not a Prime Number"Constraints:1 <= INPUT <=10^15Sample Input 1:31Sample Output 1:Prime NumberSample Input 2:2Sample Output 2:Prime NumberSample Input 3:15Sample Output 3:Not a Prime Number

What are looping statements. Write a program to check whether a number is prime no. or not.

Write a program primes.py that reads a positive integer from standard input, and determines whether or not the number is prime.

The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.OutputFor every test case print all prime numbers p such that m <= p <= n, one number per line, test cases separated by an empty line.ExampleInput:21 103 5Output:235735

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.