0
$\begingroup$

For this code:

   a = IntegerExponent[k,7]; (*a is highest power of 7 that divides k*)

I would like to find b, where b is:

   b = IntegerPower[k,7]; (*b is highest power of 7 that is less than k*)

Is there an efficient way to implement a function to do that?

cheers, Jamie

$\endgroup$
0

1 Answer 1

2
$\begingroup$
IntegerPower[k_, b_] := If[IntegerQ[#], # - 1, Floor[#]] &@Rationalize[Log[b, k]];

Examples

IntegerPower[345, 7] (* Outputs 3 *)
IntegerPower[0.0028, 7] (* Outputs -4 *)
IntegerPower[100, 2] (* Outputs 6 *)
IntegerPower[0.5, 2] (* Outputs -2 *)
$\endgroup$
1
  • $\begingroup$ Imo this function is a candidate for the Wolfram Function Repository. Although modified to (b is highest power of 7 that is less than =or equal= to k). As it is quite often used. $\endgroup$ Commented Jun 20, 2023 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.