prime <- function(x)
{
i <- 2
result <- NULL
thrs <- round(sqrt(x)) + 1
while(i < thrs)
{
if(x %% i == 0)
{
result <- c(result, i)
x <- x / i
i <- 2
thrs <- round(sqrt(x)) + 1
} else
{
i <- i + 1
}
}
if(i == thrs)
{
result <- c(result, x)
}
result
}
prime(600851475143)
复杂度应该是O(n^0.5)