We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Tutorials
  3. 30 Days of Code
  4. Day 25: Running Time and Complexity

Day 25: Running Time and Complexity

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial

Objective
Today we will learn about running time, also known as time complexity. Check out the Tutorial tab for learning materials and an instructional video.

Task
A prime is a natural number greater than that has no positive divisors other than and itself. Given a number, , determine and print whether it is or .

Note: If possible, try to come up with a primality algorithm, or see what sort of optimizations you come up with for an algorithm. Be sure to check out the Editorial after submitting your code.

Input Format

The first line contains an integer, , the number of test cases.
Each of the subsequent lines contains an integer, , to be tested for primality.

Constraints

Output Format

For each test case, print whether is or on a new line.

Sample Input

3
12
5
7

Sample Output

Not prime
Prime
Prime

Explanation

Test Case 0: .
is divisible by numbers other than and itself (i.e.: , , , ), so we print on a new line.

Test Case 1: .
is only divisible and itself, so we print on a new line.

Test Case 2: .
is only divisible and itself, so we print on a new line.

Author

blondiebytes

Difficulty

Medium

Max Score

30

Submitted By

112056

Need Help?


View tutorial
View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy