算法
2thing
这个作者很懒,什么都没留下…
展开
-
Project Euler每帖一题(001)
[quote]题目: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.[/...原创 2011-05-10 20:44:31 · 98 阅读 · 0 评论 -
Project Euler每帖一题(002)
题目: [quote] Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... ...原创 2011-05-10 21:37:27 · 100 阅读 · 0 评论 -
Project Euler每帖一题(006)
题目: [quote] The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)2 = 552 = 3025 ...原创 2011-05-11 08:49:01 · 157 阅读 · 0 评论 -
Project Euler每帖一题(005)
题目: [quote]2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the nu...原创 2011-05-11 10:34:32 · 113 阅读 · 0 评论 -
筛减法求素数
这种方法的求素数的效率很高 [code="c"]#include #include /*筛选法求素数,即质数 素数是只能被1和自身整除的数 从2开始递增,删除此数的倍数,则以后出现的就都是素数了 */ int main(int argc, char *argv[]) { //atoi函数将字符串转化为长整型 int i, j, N = atoi(a...原创 2011-07-01 14:22:42 · 159 阅读 · 0 评论 -
投硬币概率模拟程序
[code="c"] #include #include //头像面朝上的概率 int heads() { return rand() < RAND_MAX/2; } int main(int argc, char *argv[]) { int i, j, cnt; //N为每次实验投币的次数,M为实验的次数 int N = atoi(argv[1...原创 2011-07-01 14:31:50 · 1033 阅读 · 0 评论