Answer to Question #92391 in Python for AKHILA

Question #92391
Consider the following function f.

def f(n):
s=0
for i in range(1,n+1):
if n%i == 0:
s = s+1
return(s%2 == 1)
The function f(n) given above returns True for a positive number n if and only if:

n is an odd number.
n is a prime number.
n is a composite number.
n is a perfect square.
1
Expert's answer
2019-08-08T09:56:07-0400

The code counts number of divisors of given N, and returns true if it's odd.

Let D be a divisor of N, so N/D is also a divisor. So every divisor has its own pair. But if the number of them is odd, D == N/D, and N is a perfect square


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS