Trial Multiplication for Factorization
What is slow is to create seq(q_start,number,1). Take the example where  number is 298,716,239: you are asking R to create a vector of nearly 300 million integers. It chokes. Instead of looping over sequences created in memory, it is easier to just keep the current value, increment and limit in memory. See for example:

TM &lt;- function (n) {

   n &lt;- as.integer(n)
   r &lt;- sqrt(n)
   p &lt;- as.integer(floor(r))
   q &lt;- as.integer(ceiling(r))

   while (p &gt;= 1L &amp; q &lt;= n) {
      if (p * q == n) return(c(p, q)) 
      if (p * q &gt; n) { p &lt;- p - 1L } else { q &lt;- q + 1L } 
   }
   stop("hmm... we should not be here...")
}

TM(1900)
TM(298716239)


Now that's a start... If you try with a large prime, e.g. 298716247, it will take a very long time to converge towards 1 * 298716247 though. So you will have to get more creative to make it converge faster. At least, you should be fixed about why your original code was so slow.



Edit: here is an idea I got for making it converge faster where you update both p and q at each iteration. I hope the math checks out and I did not leave a corner case:

TM2 &lt;- function (n){

   n &lt;- as.integer(n) # everything is faster with integers
   r &lt;- sqrt(n)
   p &lt;- as.integer(floor(r))
   q &lt;- as.integer(ceiling(r))
   while (p &gt;= 1L &amp; q &lt;= n) {
      if (p * q == n) return(c(p, q)) 
      if (p*q &gt; n) {
         p &lt;- p - 1L
         q &lt;- as.integer(floor(n / p))
      } else {
         q &lt;- q + 1L
         p &lt;- as.integer(ceiling(n / q))
      } 
   }
   stop("hmm...")
}

TM2(1900)
TM2(298716239)
TM2(298716247)