View Single Post
Old 2018-05-28, 13:55   #1
irina
 
Jul 2015

48 Posts
Lightbulb algorithm for factoring a number into two factors

var k,l,n,s,j,d,c,y,r,b:biginteger;
begin
var x:=ReadString('введите число:').ToBigInteger;
var a:=x div 2;
repeat
b:=a;
a:=(a+x div a)div 2
until a>=b;
s:=a;
n:=x-sqr(s);
k:=n div s; j:=n mod s; l:=s+k; d:= s-j;
repeat
s:=s-1;
d:=d-1;
r:=l-d;
c:=r div s;
y:=r mod s;
l:=l+1+c;
j:=y;
d:=s-j;
until j=0;
writeln('l=',l); writeln ('s=',s);
end.
irina is offline   Reply With Quote