Puzzle 8-13-2008 (answers)
Steven Schveighoffer
schveiguy at yahoo.com
Wed Aug 13 13:00:39 PDT 2008
"BCS" wrote
> Reply to Steven,
>> void prob2()
>> {
>> auto target= 600_851_475_143;
>> for(ulong i = 3; i * i < target; i++)
>> if(target % i == 0)
>> {
>> Stdout(i).newline;
>> return;
>> }
>> Stdout(target)(" is prime!").newline;
>> }
>
> doesn't that find the smallest factor?
Correction, smallest *prime* factor (which is also the smallest factor) :)
Of course, I now realize that I misread the question...
Quick change to my code:
void prob2()
{
auto target= 600_851_475_143;
for(ulong i = 3; i * i <= target; i++)
while(target % i == 0)
{
target /= i;
}
Stdout(target).newline;
}
New answer to 2:
6857
new times (pretty much the same):
real 0m0.004s
user 0m0.003s
sys 0m0.001s
-Steve
More information about the Digitalmars-d-learn
mailing list