Algorithms and Data Structures

  • Profound Academy

    • Status
      • 1
        Implementation
      • 2
        Bitwise operations
      • 3
        Prefix Sums
      • 4
        Sliding window / Two pointers
      • 5
        Modular Arithmetic
      • 6
        Number Theory
      • 7
        Binary Search
      • 8
        Basic Sorting
      • 9
        Greedy Algorithms
      • 10
        Basic Dynamic Programming
      • 11
        Recursion
      • 12
        Linked LIst
      • 13
        Queue & Stack
      • 14
        Binary tree + BST
      • 15
        Divide & Conquer + Advanced Sorting
      • 16
        Heap
      • 17
        Hashing
      • 18
        Graph Representation

  • Check if a number is prime

    A number is considered prime if it’s divisible by only 2 numbers: 1 and itself.
    So, numbers like 3, 7, or 19 are prime (3 is only divisible by 1 and 3, 7 is only divisible by 1 and 7, and 19 is similarly divisible by only 1 and 19). While the numbers 4, 6, 8, or 49 are not prime as they are divisible by other numbers as well (4 is also divisible by 2, 6 is also divisible by 2 and 3, and 49 is also divisible by 7).
    Is 1 a prime number?
    No - 1 is divisible by only 1. For a number to be prime, it has to be divisible by exactly 2 numbers. So, the smallest prime number is 2.
    You are asked to write a program that given a positive integer n would decide if it’s a prime number.

    Input

    The first line of the input contains a single integer n (1 ≤ n ≤ ).

    Output

    The program should print Yes in case n is prime and No otherwise.

    Examples

    Input
    Output
    8
    No
    7
    Yes
    1
    No
    19
    Yes
     

    Constraints

    Time limit: 1 seconds

    Memory limit: 512 MB

    Output limit: 1 MB

    To check your solution you need to sign in
    Sign in to continue