10 May 2011

Euler Project1 欧拉工程1



欧拉工程是一个用编程来解决一连串数学问题的项目。发现它对训练数学及编程挺有作用的。网上也有许多人做上面的题目并发布自己的算法。

上面共有337题,分几个等级,一级比一级难。完成它绝对是时间及精力及耐力及智力的较量。

解决问题的代码贴在这里.主要用matlab,偶尔python,很少c/c++.有时会matlab调python解决,只为快速解决问题. Question 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.
解决
%% sum of number below 1000 and can be divided by 3 or 5
% Elapsed time is 0.002665 seconds.
% ans =
% 233168
function result = euler1()
tic
result = sum(unique([3:3:1000,5:5:999]))
toc;
end

No comments :

Post a Comment