
object Main extends App {
  import scala.io.StdIn._
  val Array(p, q) = readLine.trim.split(' ').map(_.toLong)
  val g = gcd(p, q)
  println(
    primeFactors(q / g).foldLeft(1L){case (r, n) ⇒ r * n}
  )
  def primeFactors(num: Long): List[Long] = {
    var n = num
    var res = Nil: List[Long]
    var count = 2
    while (n != 1 && count * count <= num){
      if (n % count == 0){
        res ::= count
        while (n % count == 0){
          n /= count
        }
      }
      count += 1
    }
    if (n == 1) res
    else n::res
  }
  def gcd(a: Long, b: Long): Long = {
    b match {
      case 0 ⇒ a
      case _ ⇒ gcd(b, a % b)
    }
  }
  implicit class ScopeFunc[T](private val value: T) {
    def let[A](func:T ⇒ A): A = func(value)
    def also(func:T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}

