大菠萝

大菠萝-ama+sor

和的平方与平方的和之差

Project Euler 第6题

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

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 385 = 2640.

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

哈哈,这个题目最最简单咯,一句话Python搞定。老外的自然数好像不包括0,我的理解,前100个自然数应该为[0,99]嘛。。

sum(range(101))**2-sum(i*i for i in range(101))

tags: ,,

Posted by benben on November 20,2008 3 PM in 程序设计 |Comment(0)

寻找能被1-20整除的最小数

Project Euler 第5题

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 number that is evenly divisible by all of the numbers from 1 to 20?

我使用的方法为为O(n2),附带的pdf里的算法更快,我有点没看明白。

相关下载:

tags: ,,

Posted by benben on November 20,2008 2:49 PM in 程序设计 |Comment(0)

寻找最大回文数字

Project Euler 第4题

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.

Find the largest palindrome made from the product of two 3-digit numbers.

回文数(palindromic number)是值是指类似121对称的数字,将该数按照相反的顺序排列后,所得到的数和原来的一样。

在Python,判断是否回文的办法:

def ispalindrom(num):
    num=str(num)
    return num==num[::-1]

完整代码见:large-palindrome-made-from-3-digit.py

相关下载:

tags: ,,

Posted by benben on November 20,2008 10:43 AM in 程序设计 |Comment(0)

注册超短189邮箱

189为中国电信未开通邮箱,用户名最短为5位。官方验证不严,可以手工提交数据包,注册超短的用户名(1位-5位)。

使用工具Firefox+Live HTTP headers。

过程:

1.注册一邮箱,提交时使用Live HTTP headers抓取提交的数据包。

2.使用Live HTTP headers 的Realay 功能,只需修改两个提交变量。userName=后面改为你需要的用户名;chkCode=为4位验证码,刷新一下注册页面,把那个填进来即可。

3.提交,你就可以获取一个超短的邮箱啦。

参考文章:获取隐藏网络服务API的方法总结

注册地址:http://webmail.189.cn/webmail/groupehomemail_register.jsp

tags: ,

Posted by benben on November 19,2008 8:43 PM in 程序设计 |Comment(9)

最大质因数

Project Euler 第3题

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

prime factors,中文翻译为素因数(质因数)。每个合数都可以写成几个素数相乘的形式,这几个素数都叫做这个合数的素因数。比如例子中的13195=5*7*13*29。

prime number称为素数,又称质素。一个数,如果只有1和它本身两个因数,则称为素数。

我的解法为:从1开始找一个能被600851475143 整除的素数i,转化为找600851475143 /i最大质因数的问题。完整代码见:the-largest-prime-factor-of-number.py

相关下载:

tags: ,,

Posted by benben on November 19,2008 3:22 PM in 程序设计 |Comment(4)


e.g. "大菠萝"