0
$\begingroup$

I am required to implement this code function but I have no idea what it is asking for. Can someone explain this to me in simpler terms so that I can try to turn it into code?

Given $x$ and $y$, I need to return $Z$.

The description of the function:

If $x$ can be expressed as $x=qy^n$, then $z = q$ i.e. remove factor $y$ from the number $x$, such that $z$ no longer has $y$ as a factor.

Some example results:

x: 2835, y = 3, result = 35

x: 2357, y = 19, result = 2357

I just need a clearer idea of what they are actually asking for.

Thank you

$\endgroup$
5
  • 1
    $\begingroup$ hint: divide $x$ by $y$ (without remainder) as often as possible and return the result $\endgroup$ Jan 28, 2021 at 12:39
  • 3
    $\begingroup$ You also need to express clearer what you are actually asking for. I'm guessing this: "Yn" is a very sloppy way to write $Y^n$ and in $X=Y^n\,Q$ you are assuming (without telling us) that $Q$ is not divisble by $Y$, so that we really removed as many factors of $Y$ as possible. Please edit your question to clarify this and also make use of MathJax for typesetting formulas. – We shouldn't have to guess what you might want to ask, be precise. $\endgroup$
    – Christoph
    Jan 28, 2021 at 12:44
  • $\begingroup$ As @Christoph said, what is $Yn*Q$ supposed to be? This wasn't clear when I was trying to edit your post. $\endgroup$ Jan 28, 2021 at 12:46
  • 1
    $\begingroup$ Raymond has the correct idea. You take the initial number (2835) and put it on a loop. In each loop, you check if it's divisible by $y$ ($y=3$ in the example) and if it is, then divide the number in the loop by that number. When it no longer is divisible, then exit the loop and return the final number. Pretty easy, it's like 4 or 5 lines of code. $\endgroup$
    – Matti P.
    Jan 28, 2021 at 13:21
  • $\begingroup$ @MattiP. and RaymondManzoni Thank you so much! This was actually what they were asking for. I always have problems deciphering math problems, even such simple ones. Can you tell me how you derived this? I know it's easy. But from reading the description given (and not doing any test on the inputs), I had no idea this was what they were asking. [at]the rest: my apologies for missing out on the correct formatting. I forgot to ensure that the superscripts were intact after including the question. $\endgroup$
    – Iva l
    Jan 28, 2021 at 13:53

1 Answer 1

0
$\begingroup$

The solution was to simply divide the x value as much as possible by y, and return the final divisible value.

Thank you to the kind souls for helping me out! Point noted on the formatting in future.

$\endgroup$

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