楼主: tree_new_bee

Euler Project 挨个做 - 之一(Q1-50)

[复制链接]
论坛徽章:
10
CTO参与奖
日期:2009-02-20 09:44:20ITPUB年度最佳技术原创精华奖
日期:2013-03-22 13:18:30迷宫蛋
日期:2012-05-07 10:55:58茶鸡蛋
日期:2012-04-19 16:08:262012新春纪念徽章
日期:2012-01-04 11:54:462011新春纪念徽章
日期:2011-01-04 10:24:02数据库板块每日发贴之星
日期:2010-12-19 01:01:02数据库板块每日发贴之星
日期:2010-12-13 01:01:012009日食纪念
日期:2009-07-22 09:30:00优秀写手
日期:2014-02-08 06:00:12
241#
 楼主| 发表于 2010-12-28 11:21 | 只看该作者
这个题不难。 只是边界需要试探。

with todd as (select rownum*2+1 n from dual connect by rownum<=10000/6)
,toddcomp as (select  distinct t1.n*t2.n o from todd t1,todd t2 where t1.n<=t2.n and t1.n*t2.n<=10000)
, tprim as (select  column_value prim from table(pkg_prim2.seive_numlist(10000)))
select min(o) from toddcomp
where not exists (select 1 from tprim
where prim<toddcomp.o
and sqrt((toddcomp.o - prim)/2) = trunc(sqrt((toddcomp.o - prim)/2))
)

    MIN(O)
----------
      5777

Executed in 114.921 seconds

数据量并不大,这么慢有点出乎预料之外。
估计应该又是优化器惹的祸。 用上面的MATERIALIZE试试



with todd as (select rownum*2+1 n from dual connect by rownum<=10000/6)
,toddcomp as (select /*+ MATERIALIZE */ distinct t1.n*t2.n o from todd t1,todd t2 where t1.n<=t2.n and t1.n*t2.n<=10000)
, tprim as (select /*+ MATERIALIZE */ column_value prim from table(pkg_prim2.seive_numlist(10000)))
select min(o) from toddcomp
where not exists (select 1 from tprim
where prim<toddcomp.o
and sqrt((toddcomp.o - prim)/2) = trunc(sqrt((toddcomp.o - prim)/2))
)

    MIN(O)
----------
      5777

Executed in 1.594 seconds

这下可以接受了。

使用道具 举报

回复
论坛徽章:
10000
绿钻
日期:2016-02-22 15:43:08绿钻
日期:2016-03-01 18:19:01绿钻
日期:2016-02-22 15:43:08绿钻
日期:2016-03-01 18:19:01绿钻
日期:2015-12-16 18:42:35绿钻
日期:2015-12-11 00:18:01绿钻
日期:2015-09-10 13:05:08绿钻
日期:2015-12-11 00:18:01绿钻
日期:2015-09-10 13:05:08绿钻
日期:2015-09-10 13:05:08
242#
发表于 2010-12-28 11:21 | 只看该作者
楼主11g的递归with都用得那么如火纯清了。。
高等数据也那么牛。。。
偶个高中毕业的, IQ也不高,想写也写不出来。。

使用道具 举报

回复
论坛徽章:
10
CTO参与奖
日期:2009-02-20 09:44:20ITPUB年度最佳技术原创精华奖
日期:2013-03-22 13:18:30迷宫蛋
日期:2012-05-07 10:55:58茶鸡蛋
日期:2012-04-19 16:08:262012新春纪念徽章
日期:2012-01-04 11:54:462011新春纪念徽章
日期:2011-01-04 10:24:02数据库板块每日发贴之星
日期:2010-12-19 01:01:02数据库板块每日发贴之星
日期:2010-12-13 01:01:012009日食纪念
日期:2009-07-22 09:30:00优秀写手
日期:2014-02-08 06:00:12
243#
 楼主| 发表于 2010-12-28 11:23 | 只看该作者
上面是用奇合数-质数,看是否是平方数。
下面改成用奇合数-平方数, 看是否是质数。

with todd as (select rownum*2+1 n from dual connect by rownum<=10000/6)
,toddcomp as (select  distinct t1.n*t2.n o from todd t1,todd t2 where t1.n<=t2.n and t1.n*t2.n<=10000)
,tsqr as (select rownum*rownum s from dual connect by rownum*rownum<=10000)
select min(o) from toddcomp
where not exists (select 1 from tsqr
where 2*s<toddcomp.o
and pkg_prim2.isprim(toddcomp.o-2*s) = 0
)

    MIN(O)
----------
      5777

Executed in 1.656 seconds

这次不加提示也很快。

使用道具 举报

回复
论坛徽章:
10
CTO参与奖
日期:2009-02-20 09:44:20ITPUB年度最佳技术原创精华奖
日期:2013-03-22 13:18:30迷宫蛋
日期:2012-05-07 10:55:58茶鸡蛋
日期:2012-04-19 16:08:262012新春纪念徽章
日期:2012-01-04 11:54:462011新春纪念徽章
日期:2011-01-04 10:24:02数据库板块每日发贴之星
日期:2010-12-19 01:01:02数据库板块每日发贴之星
日期:2010-12-13 01:01:012009日食纪念
日期:2009-07-22 09:30:00优秀写手
日期:2014-02-08 06:00:12
244#
 楼主| 发表于 2010-12-28 11:26 | 只看该作者
原帖由 jboracle1981 于 2010-12-28 11:21 发表
楼主11g的递归with都用得那么如火纯清了。。
高等数据也那么牛。。。
偶个高中毕业的, IQ也不高,想写也写不出来。。


做这些题用的数学知识里,没有超过高中程度的内容。

再说了, 超过高中数学程度的东西, 我也早忘光了, 想用也用不上。

使用道具 举报

回复
论坛徽章:
5
2010新春纪念徽章
日期:2010-03-01 11:20:51ITPUB学员
日期:2010-04-14 14:24:31ITPUB学员
日期:2010-08-21 18:20:28ITPUB9周年纪念徽章
日期:2010-10-08 09:31:212011新春纪念徽章
日期:2011-02-18 11:42:49
245#
发表于 2010-12-28 16:22 | 只看该作者
以NB哥为榜样,好好学习开发知识,年前就研究这篇帖子了

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
246#
发表于 2010-12-28 21:24 | 只看该作者
问题55:
How many Lychrel numbers are there below ten-thousand?
题目简介:首先介绍一个数学名词:利克瑞尔数(Lychrel Number):指的是将该数与将该数各数位逆序翻转
后形成的新数相加、并将此过程反复迭代后,结果永远无法是一个回文数的自然数。
  现在已知对于10000以内的自然数,要么能够在50步(指将这个数与其逆序后的数相加的过程)内得到一
个回文数;要么该数是一个利克瑞尔数。
  求:10000以内利克瑞尔数的个数
答  案:249

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
247#
发表于 2010-12-28 21:24 | 只看该作者
问题56:Considering natural numbers of the form, a^b, finding the maximum digital sum.
题目简介:记f(x)表示自然数x的各位数字之和,a^b表示a的b次方。对1≤a,b <100,求f(a^b)的最大值。
答  案:972

使用道具 举报

回复
论坛徽章:
10
CTO参与奖
日期:2009-02-20 09:44:20ITPUB年度最佳技术原创精华奖
日期:2013-03-22 13:18:30迷宫蛋
日期:2012-05-07 10:55:58茶鸡蛋
日期:2012-04-19 16:08:262012新春纪念徽章
日期:2012-01-04 11:54:462011新春纪念徽章
日期:2011-01-04 10:24:02数据库板块每日发贴之星
日期:2010-12-19 01:01:02数据库板块每日发贴之星
日期:2010-12-13 01:01:012009日食纪念
日期:2009-07-22 09:30:00优秀写手
日期:2014-02-08 06:00:12
248#
 楼主| 发表于 2010-12-28 22:53 | 只看该作者
原帖由 〇〇 于 2010-12-28 21:24 发表
问题55:


怎么一下子跳到55了?
这不是逼着我赶进度吗?

使用道具 举报

回复
论坛徽章:
10
CTO参与奖
日期:2009-02-20 09:44:20ITPUB年度最佳技术原创精华奖
日期:2013-03-22 13:18:30迷宫蛋
日期:2012-05-07 10:55:58茶鸡蛋
日期:2012-04-19 16:08:262012新春纪念徽章
日期:2012-01-04 11:54:462011新春纪念徽章
日期:2011-01-04 10:24:02数据库板块每日发贴之星
日期:2010-12-19 01:01:02数据库板块每日发贴之星
日期:2010-12-13 01:01:012009日食纪念
日期:2009-07-22 09:30:00优秀写手
日期:2014-02-08 06:00:12
249#
 楼主| 发表于 2010-12-28 22:55 | 只看该作者
Q47  Find the first four consecutive integers to have four distinct primes factors.

The first two consecutive numbers to have two distinct prime factors are:

14 = 2 × 7
15 = 3 × 5

The first three consecutive numbers to have three distinct prime factors are:

644 = 2² × 7 × 23
645 = 3 × 5 × 43
646 = 2 × 17 × 19.

Find the first four consecutive integers to have four distinct primes factors. What is the first of these numbers?

使用道具 举报

回复
论坛徽章:
10
CTO参与奖
日期:2009-02-20 09:44:20ITPUB年度最佳技术原创精华奖
日期:2013-03-22 13:18:30迷宫蛋
日期:2012-05-07 10:55:58茶鸡蛋
日期:2012-04-19 16:08:262012新春纪念徽章
日期:2012-01-04 11:54:462011新春纪念徽章
日期:2011-01-04 10:24:02数据库板块每日发贴之星
日期:2010-12-19 01:01:02数据库板块每日发贴之星
日期:2010-12-13 01:01:012009日食纪念
日期:2009-07-22 09:30:00优秀写手
日期:2014-02-08 06:00:12
250#
 楼主| 发表于 2010-12-28 22:58 | 只看该作者
又要质因数分解。
这种题用SQL总是有种无力的感觉。

SQL:

with targ as (select 200000 arg from dual)
,t1 as (select /*+ MATERIALIZE */ rownum n from targ connect by rownum<=arg)
,t2 as (select /*+ MATERIALIZE */ column_value d from targ, table(pkg_prim2.seive_numlist((arg/2))))
,t3 as (select n, count(d)  dn
from  t1, t2 where n>d and mod(n, d) = 0 group by n having count(d)=4 )
--select * from t3 where dn=3
select connect_by_root(n) from t3 where  level=4 connect by n=prior n+1  


放到那里不管它, 看看多久能出来结果。

CONNECT_BY_ROOT(N)
------------------
            134043

Executed in 1835.078 seconds

SQL>

吼吼, 跑了半个小时!

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表