Project Euler problem 62
题目的大意很简单
做法的话。
我们就枚举1~10000的数的立方,
然后把这个立方中的有序重新排列,生成一个字符串s, 然后对于那些符合题目要求的肯定是生成同一个字符串的。
然后就可以用map来搞了
这里偷懒用了python
import string
dic = {}
def getstr(n):
sn = str(n)
arr = []
for c in sn:
arr.append(c)
arr.sort()
return ''.join(arr)
for i in xrange(1, 10000):
s = getstr(i**3)
if s in dic:
dic[s] += 1
else:
dic[s] = 1
a = []
for d in dic:
if dic.get(d) == 5:
a.append(d)
k = min(a)
for i in xrange(1, 10000):
s = getstr(i**3)
if dic[s] == 5:
print i, i**3
Project Euler problem 62的更多相关文章
- Project Euler Problem 10
Summation of primes Problem 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of ...
- Project Euler problem 63
这题略水啊 首先观察一下. 10 ^ x次方肯定是x + 1位的 所以底数肯定小于10的 那么我们就枚举1~9为底数 然后枚举幂级数就行了,直至不满足题目中的条件即可break cnt = 0 for ...
- Project Euler problem 61
题意很明了. 然后我大概的做法就是暴搜了 先把每个几边形数中四位数的处理出来. 然后我就DFS回溯着找就行了. 比较简单吧. #include <cstdio> #include < ...
- Project Euler problem 68
题意须要注意的一点就是, 序列是从外层最小的那个位置顺时针转一圈得来的.而且要求10在内圈 所以,这题暴力的话,假定最上面那个点一定是第一个点,算下和更新下即可. #include <iostr ...
- Project Euler Problem 675
ORZ foreverlasting聚聚,QQ上问了他好久才会了这题(所以我们又聊了好久的Gal) 我们先来尝试推导一下\(S\)的性质,我们利用狄利克雷卷积来推: \[2^\omega=I\ast| ...
- Project Euler Problem (1~10)
1.If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. Th ...
- Project Euler Problem 26-Reciprocal cycles
看样子,51nod 1035 最长的循环节 这道题应该是从pe搬过去的. 详解见论文的(二)那部分:http://web.math.sinica.edu.tw/math_media/d253/2531 ...
- Project Euler Problem 24-Lexicographic permutations
全排列的生成,c++的next_permutation是O(n)生成全排列的.具体的O(n)生成全排列的算法,在 布鲁迪 的那本组合数学中有讲解(课本之外,我就看过这一本组合数学),冯速老师翻译的,具 ...
- Project Euler Problem 23-Non-abundant sums
直接暴力搞就行,优化的地方应该还是计算因子和那里,优化方法在这里:http://www.cnblogs.com/guoyongheng/p/7780345.html 这题真坑,能被写成两个相同盈数之和 ...
随机推荐
- bootstrap日期时间插件datetimepicker
<!DOCTYPE HTML> 02 <html> 03 <head> 04 <link href="http://netdna.boo ...
- openerp 中如何方便对搜索时间段
以前为了方便的搜索时间区间,经常用wizard对方式,设置开始 结束时间,需要做大量对代码工作, 今天看了search view对组成, 可以用2个filter_domain 来做, 这样用户需要输 ...
- jquery获取元素的所有宽高(包括内边距和外边距)
width() - 返回元素的宽度.height() - 返回元素的高度.innerWidth() 方法返回元素的宽度(包括内边距). innerHeight() ...
- windows系统安装ubuntu后,grub中没有windows启动项
我的问题: 安装系统时候,选择grub安装在sdb磁盘 http://forum.ubuntu.org.cn/viewtopic.php?f=139&t=474289&start=15 ...
- Rss web 工具 大对比
今天终于神受不了 feedly的链接死掉了..有时候挂代理就好了..但是麻烦. 于是: AOL reader Digg reader feedly 对比下.使用了一天 1.feedly 优: 效果最 ...
- python 性能鸡汤
转载自:http://www.oschina.net/question/1579_45822 1:使用内建函数input() int() isinstance() issubclass() iter( ...
- c# appdomain
http://www.cnblogs.com/Terrylee/archive/2005/11/28/285809.html
- 【Java】String,StringBuffer与StringBuilder的区别??
String 字符串常量StringBuffer 字符串变量(线程安全)StringBuilder 字符串变量(非线程安全) 简要的说, String 类型和 StringBuffer 类型的主要性能 ...
- java interface
- poj 2432 Around the world bfs+哈希
由于每个点的状态包含走过来的距离,所以要存二维的状态,但是状态总量太多,所以可以用哈希来搞. 那么就是bfs最短路,哈希记录状态了. #include <iostream> #includ ...