diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-19 20:46:58 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-19 20:46:58 +0100 |
| commit | ddc172aaede1c9d6d2e62c9f7dba2884f7ca2843 (patch) | |
| tree | 96650ed584c22576d5009e1326d21e5440ed1ef4 /challenge-066/paulo-custodio/python/ch-2.py | |
| parent | 7c7ea0c93086bd4d0709fdffe7422a7f3a9bfdca (diff) | |
| parent | 367848e4502bb070efae0688c3f340015e411773 (diff) | |
| download | perlweeklychallenge-club-ddc172aaede1c9d6d2e62c9f7dba2884f7ca2843.tar.gz perlweeklychallenge-club-ddc172aaede1c9d6d2e62c9f7dba2884f7ca2843.tar.bz2 perlweeklychallenge-club-ddc172aaede1c9d6d2e62c9f7dba2884f7ca2843.zip | |
Merge pull request #10871 from pauloscustodio/master
Add Python solution to challenge 066
Diffstat (limited to 'challenge-066/paulo-custodio/python/ch-2.py')
| -rw-r--r-- | challenge-066/paulo-custodio/python/ch-2.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/challenge-066/paulo-custodio/python/ch-2.py b/challenge-066/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..50d2aa2100 --- /dev/null +++ b/challenge-066/paulo-custodio/python/ch-2.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +# Challenge 066 +# +# TASK #2 > Power Integers +# Submitted by: Mohammad S Anwar +# +# You are given an integer $N. +# +# Write a script to check if the given number can be expressed as mn where m and +# n are positive integers. Otherwise print 0. +# +# Please make sure m > 1 and n > 1. +# +# BONUS: If there are more than one ways to express the given number then print +# all possible solutions. +# +# Example 1: +# For given $N = 9, it should print 32 or 3^2. +# +# Example 2: +# For given $N = 45, it should print 0. +# +# Example 3: +# For given $N = 64, it should print all or one of 8^2 or 2^6 or 4^3. + +import sys +from math import sqrt + +def show_powers(n): + has_solution = False + for b in range(2, int(sqrt(n))+1): + for e in range(2, n): + if b**e == n: + print(str(b)+"^"+str(e)) + has_solution = True + if not has_solution: + print(0) + +N = int(sys.argv[1]) +show_powers(N) |
