Advertisement
aseeshr

Get Exponent

Nov 21st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. 1. Write a method named getExponent(n, p) that returns the largest exponent x such that px evenly divides n. If p is <= 1 the method should return -1.
  2.  
  3. For example, getExponent(162, 3) returns 4 because 162 = 21 * 34, therefore the value of x here is 4.
  4.  
  5. The method signature is
  6. int getExponent(int n, int p)
  7.  
  8. Examples:
  9.  
  10. if n is
  11. and p is
  12. return
  13. because
  14. 27
  15. 3
  16. 3
  17. 33 divides 27 evenly but 34 does not.
  18. 28
  19. 3
  20. 0
  21. 30 divides 28 evenly but 31 does not.
  22. 280
  23. 7
  24. 1
  25. 71 divides 280 evenly but 72 does not.
  26. -250
  27. 5
  28. 3
  29. 53 divides -250 evenly but 54 does not.
  30. 18
  31. 1
  32. -1
  33. if p <=1 the function returns -1.
  34. 128
  35. 4
  36. 3
  37. 43 divides 128 evenly but 44 does not.
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement