-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kalpak Take
authored
Feb 11, 2017
1 parent
17e129e
commit 5a047f1
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" Function uses prime factorisation method | ||
to find square root of number """ | ||
|
||
def prime_factors(c): | ||
pos = 2 | ||
factors = [] | ||
while (pos <= c): | ||
if (c % pos == 0): | ||
c = c // pos | ||
factors.append(pos) | ||
continue | ||
else: | ||
pos = pos + 1 | ||
return factors | ||
|
||
def extract_common(li): | ||
final = [] | ||
if (len(li) % 2 != 0): | ||
return "Number is not perfect root." | ||
else: | ||
pre = len(li) - 1 | ||
for n in range(0, pre, 2): | ||
a = li[n] | ||
b = li[n + 1] | ||
if (a == b): | ||
final.append(b) | ||
else: | ||
return "Number is not perfect root." | ||
return final | ||
|
||
def square_root(take_in): | ||
res = 1 | ||
for c in take_in: | ||
res *= c | ||
return res | ||
|
||
get_num = int(raw_input("\nNumber : ")) | ||
print square_root(extract_common(prime_factors(get_num))), " " |