Hackerrank “30 Days of Code” Çözümleri – Day 25: Running Time and Complexity

Hackerrank’in 30 Days of Code içerisinde bulunan “Day 25: Running Time and Complexity” sorusunun açıklaması ve çözümü. Bu soruda size verilen sayının bir asal sayı olup olmadığını, time complexity kavramını anlatarak bulmanız isteniyor.

► Hackerrank 30 Days of Code Çözümleri – Day 25: Running Time and Complexity: https://www.hackerrank.com/challenges/30-running-time-and-complexity/problem

► Problem açıklaması:


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


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

Note: If possible, try to come up with a squareRoot(n) primality algorithm, or see what sort of optimizations you come up with for an O(n) 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.

Output Format

For each test case, print whether n is Prime or Not prime on a new line.

Sample Input





Sample Output

Not prime



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.