Jump to content

Largest Square Factor

Featured Replies

I need to write a function to find the largest square factor of a number so it can be taken out of a radical. I hope there is a known solution to this.

 

The most efficient aproach I can think of is:

 

set total to 1
for (each prime less than square root of n) {
 while (n is divisble by prime^2) {
   divide n by prime^2
   multiply total by prime
 }
}

"total" should then be a square factor of n. The problem with this is that it is very slow. Is there a faster method?

Total is not a sqaure factor of n, unless I misunderstand what 'square factor' means, ie a factor that is a square. total is not a square. total will be a square root of a square factor.

 

in anycase, how are you using this? because it seems to me that given N you put N in, and get N' out but then you need to put N' in again, and so on until it outputs what you input.

 

This seems unwieldy. Firstly, your program should run something we'll label 'IsSquare( )', then it should at the very least do something like:

 

 

if p divides N work out largest power of p that divides N, if even exponent do something if odd do sometihng

 

 

however, this essentially factors N, so you might as well just ask for the factorization and read off the answer.

 

 

what size input are you considering and what length of time do you need to do this in?

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.