Fokoel
6/7/2019 - 1:40 PM

Project Euler - 3. Наибольший простой делитель

import math
n=”600851475143”
if n mod 2=0
  then
  lastFactor=2
  n=n div 2
  while n mod 2=0
    n=n div 2
  else
    lastFactor=1
factor=3
maxFactor=math.sqrt(n)
while n>1 and factor<=maxFactor
    if n mod factor=0
      then
        n=n div factor
        lastFactor=factor
        while n mod factor=0
          n=n div factor
        maxFactor=math.sqrt(n)
    factor=factor+2
if n=1
    then
      output lastFactor
    else
      output n