#! perl -w
$m="135066410865995223349603216278805969938881475605667027524485143851526510604859533833940287150571909441798207282164471551373680419703964191743046496589274256239341020864383202110372958725762358509643110564073501508187510676594629205563685529475213500852879416377328533906109750544334999811150056977236890927563"; #rsa1024

$m="1230186684530117755130494958384962720772853569595334792197322452151726400507263657518745202199786469389956474942774063845925192557326303453731548268507917026122142913461670429214311602221240479274737794080665351419597459856902143413"; #rsa768 

$m="74037563479561712828046796097429573142593188889231289084936232638972765034028266276891996419625117843995894330502127585370118968098286733173273108930900552505116877063299072396380786710086096962537934650563796359"; #rsa704

#$m="10000000000000000000000000000";
$mmax=20000;
$amax=2000;
$b1max=1000;
$loop=20;
print "m=$m\n";
@F=split //,$m;
for(@F) {
  $sum+=$_;
}
print "digit sum=$sum\n";
print "mmax $mmax amax $amax b1max $b1max loop $loop\n";
$runs=0;
while(1){
  $a=1+int(rand($mmax));
  $b=1+int(rand($amax));
  unless (gcd($a,$b)==1) {
    print "skipping $a $b\n";
    next;
  }
  if ((rand(2))>1) {
    $sign="+";
  }
  else {
    $sign="-";
  }
  $_=`echo $m*$a$sign$b | ecm -c $loop $b1max`; $runs++;
  s/$m/m/g;  s/^XRun .*\n//mg; s/^Step [12] took.*\n//mg;s/Using B1=.*\n//mg;s/^GMP-ECM 6.*\n//;  print;
@e=times;
  $avg=$e[2]/$runs;
  print "time=$e[2]";
  printf("%5.2f\n",$avg);

}

sub gcd { my ($m, $n) = @_; if ($n == 0) { return $m; } return gcd($n, $m % $n); }
