Puzzle 8-13-2008

BCS ao at pathlink.com
Wed Aug 13 13:35:17 PDT 2008


Reply to wyverex,

> Steven Schveighoffer wrote:
> 
>> 1472 is not prime.
>> 
>> Hint for doing prime stuff, don't use floating point types :)
>> 
>> Also, the second to last line, taking the max of l and m is
>> questionable.
>> 
>> -Steve
>> 
> Wow I messed that up!
> 
> //Proper way I should have done it!!!
> import tango.io.Stdout;
> void main()
> {
> ulong i = 600851475143;
> ulong l = 2;
> while(l*l <= i)
> {
> if(i%l == 0)
> {
> Stdout(l)(" ");
> i /= l;
> }
> ++l;
> }
> Stdout(i).newline;
> Stdout("Max:")(i).newline;
> }
> Output:
> 71 839 1471 6857
> Max:6857

that still has a slight error, if the input number has any repeated factors 
it will fail.




More information about the Digitalmars-d-learn mailing list