local fn Sigma( n as long ) as long long i, root, sum = 1 if n == 1 then exit fn = 0 root = sqr(n) for i = 2 to root if ( n mod i == 0 ) then sum += i + n/i next if root * root == n then sum -= root end fn = sum void local fn CalculateAmicablePairs( limit as long ) long i, m printf @"\nAmicable pairs through %ld are:\n", limit for i = 2 to limit m = fn Sigma(i) if ( m > i ) if ( fn Sigma(m) == i ) then printf @"%6ld and %ld", i, m end if next end fn CFTimeInterval t t = fn CACurrentMediaTime fn CalculateAmicablePairs( 20000 ) printf @"\nCompute time: %.3f ms",(fn CACurrentMediaTime-t)*1000 HandleEvents