in reply to Re: Factors
in thread Vampire Numbers
It seemed like a good idea so I cooked it up according to
your description. Correct me if I'm wrong but it seems
quadratic residues won't account for all factors.
Program correctly factors 24 to 4*6 and 2*12 but misses 3*8. Program finds no factors for 54.
YuckFoo
Update: With a little thought one can see the program will only find factor pairs that are both even or both odd. x+y * x-y = p.
#!/usr/bin/perl use strict; my ($num) = @ARGV; my $x = int(sqrt($num)) + 1; my $y = sqrt($x * $x - $num); while ($x - $y >= 2) { if ($y == sprintf("%d", $y)) { print "Ok $num = ", $x-$y, " * ", $y+$x, "\n"; } else { print "No x = $x, y = $y\n"; } $x++; $y = sqrt($x * $x - $num); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Factors
by kvale (Monsignor) on Jun 13, 2002 at 04:51 UTC | |
Re: Re: Re: Factors
by gumby (Scribe) on Jun 13, 2002 at 15:43 UTC | |
by gumby (Scribe) on Jun 15, 2002 at 19:21 UTC |
In Section
Cool Uses for Perl