Find the Next Powers Higher than a Given Value With Given Constraints
Description:
We need a function find_next_pow()
that may receive the following arguments:
val
, a positive integer valuepow_
, the value of an exponent that defines the function power()am_factors
, the required amount of the smallest factors ofval
, not including1
(andval
itself), that should have the perfect powers, took
, the wanted amount of the smallest perfect pow_ powers but higher thanval
, that fulfill the above requirement.
The function will output a sorted list of length equals to k
, with the found values.
So, the order of arguments in the function and the output will be:
find_next_pow(val, pow_, am_factors, k) == [next_pow1, next_pow2, ...., next_powk] # val < next_pow1 < next_pow2 < ..... < next_powk
Let's see some examples:
val = 1218
pow_ = 2
am_factors = 4
k = 3
find_next_pow(val, pow_, am_factors, k) == [1764, 7056, 15876]
Explanation:
factors of 1218: 2, 3, 6, 7, 14, 21, 29, 42, 58, 87, 174, 203, 406, 609
am_factors = 4 # So, we need the first 4 factors of 1218.
com_factors = [2, 3, 6 ,7]
The result, [1764, 7056, 15876], has three elements because k =3
The three terms are perfect squares as pow_ = 2.
All of them have [2, 3, 6, 7] as factors
And 1218 < 1764 < 7056 < 15876.
These three perfect squares are the smallest posible perfect 2-powers (perfect square) higher than val = 1218, that have 2, 3, 6 and 7 as factors, the first four factors of 1218.
Special cases:
If val
is a prime number, the function will return val is a prime number. No results
val = 997
pow_ = 3
am_factors = 5
k = 6
find_next_pow(val, pow_, am_factors, k) == "val is a prime number. No results."
If val
is not a prime number but the number of factors is less than am_factors
, factors of val < am_factors)
, the function will return Not enough factors of the given value. No results.
val = 1994
pow_ = 2
am_factors = 4
k = 3
find_next_pow(val, pow_, am_factors, k) == "Not enough factors of the given value. No results."
Assumptions: pow_
, am_factors
and k
will be always higher than 1
.
(Hint: See the prime factorization that a n-perfect power should have) Happy coding!!
Similar Kata:
Stats:
Created | Feb 8, 2016 |
Published | Feb 8, 2016 |
Warriors Trained | 66 |
Total Skips | 2 |
Total Code Submissions | 188 |
Total Times Completed | 12 |
Python Completions | 12 |
Total Stars | 1 |
% of votes with a positive feedback rating | 25% of 4 |
Total "Very Satisfied" Votes | 0 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 5 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |