Puzzle 8-13-2008 (answer)

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


Reply to wyverex,

> I've yet to try these but they look more challenging!
> 
> 1)  If we list all the natural numbers below 10 that are multiples of
> 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
> 
> Find the sum of all the multiples of 3 or 5 below 1000.
> 

233168

(took about 2 min with excel

int sum=0;
for(int i = 1; i < 1000; i++) if(!(i%3 && 1%5)) summ += i;

> 2)  The prime factors of 13195 are 5, 7, 13 and 29.
> 
> What is the largest prime factor of the number 600851475143 ?

6857

import std.stdio;
void main()
{
	long v = 600851475143;
	long i = 2;
	while(i < v)
		if(v%i)	i++;
		else	v/=i;
	writef("%d\n", v);
}




More information about the Digitalmars-d-learn mailing list