Hackerrank - Smart Number Solution
1 min read

Hackerrank - Smart Number Solution

Hackerrank - Smart Number Solution

In this challenge, the task is to debug the existing code to successfully execute all provided test files.


A number is called a smart number if it has an odd number of factors. Given some numbers, find whether they are smart numbers or not.

Debug the given function is_smart_number to correctly check if a given number is a smart number.

Note: You can modify only one line in the given code and you cannot add or remove any new lines.

To restore the original code in the editor, create a new buffer by clicking on the top left icon in the editor.

Input Format

The first line of the input contains , the number of test cases.
The next  lines contain one integer each.

Constraints

  • , where  is the  integer.

Output Format

The output should consist of  lines. In the  line print YES if the  integer has an odd number of factors, else print NO.

Sample Input

4
1
2
7
169

Sample Output

YES
NO
NO
YES

Explanation

The factors of 1 are just 1 itself.So the answer is YES. The factors of 2 are 1 and 2.It has even number of factors.The answer is NO. The factors of 7 are 1 and 7.It has even number of factors.The answer is NO. The factors of 169 are 1,13 and 169.It has odd number of factors.The answer is YES.

Solution in Python

import math

def is_smart_number(num):
    val = int(math.sqrt(num))
    if num / val**2 == 1:
        return True
    return False

for _ in range(int(input())):
    num = int(input())
    ans = is_smart_number(num)
    if ans:
        print("YES")
    else:
        print("NO")

Enjoying these posts? Subscribe for more


Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

That's okay. But without advertising-income, we can't keep making this site awesome.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add thepoorcoder.com to your ad blocking whitelist or disable your adblocking software.

×