Beta

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 value

  • pow_, the value of an exponent that defines the function power()

  • am_factors, the required amount of the smallest factors of val, not including 1 (and val itself), that should have the perfect powers, too

  • k, the wanted amount of the smallest perfect pow_ powers but higher than val, 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!!

Fundamentals
Data Structures
Algorithms
Mathematics
Logic
Strings

Stats:

CreatedFeb 8, 2016
PublishedFeb 8, 2016
Warriors Trained66
Total Skips2
Total Code Submissions188
Total Times Completed12
Python Completions12
Total Stars1
% of votes with a positive feedback rating25% of 4
Total "Very Satisfied" Votes0
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes2
Total Rank Assessments5
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • raulbc777 Avatar
  • bidouille Avatar
Ad