|
这个题因为涉及到的数据量小, 即使不加任何人肉判断直接暴力,也没多少计算量。 为了有趣,还是要稍稍人肉一下。
已知条件: (10a+b)/(10b+c) = a/c, a<c
上面的等式变化一下,可得:
10ac + bc = 10ab + ac
9ac + bc = 10ab
所以: b= 9ac/(10a-c) 因为a<c 所以b> 9ac/(10a-a) = 9ac/9a = c, 即b>c
因此数的大小关系为a<c<b
with t as (select rownum n from dual connect by rownum<=9)
,t1 as (select ta.n a, tb.n b, tc.n c, 10*ta.n+tb.n ab, 10*tb.n+tc.n bc from t ta, t tb ,t tc
where ta.n < tc.n and tc.n<tb.n
and 9*ta.n*tc.n +tb.n*tc.n = 10*ta.n * tb.n)
,t2 as (select round(power(10, sum(log(10, ab)))) sab, round(power(10, sum(log(10,bc)))) sbc from t1)
, gcd(a, b) as
(select sab , sbc from t2
union all
select b,
mod(a,b)
from gcd where b>0
)
select sbc/a from gcd,t2 where b=0
SBC/A
----------
100
Executed in 0.063 seconds
其实t1的结果出来后(就4个数: 16/64, 19/95, 26/65,49/98), 肉眼就能一口说出答案了, 可是为了让sql说出答案,还整的挺麻烦, 又是连乘, 又是gcd的。
真是无趣啊, 赶紧pass.
本来还想优化优化,利用b= 9ac/(10a-c),减少一次表的连接, 可是看这运行时间, 实在是不值得了。
[ 本帖最后由 tree_new_bee 于 2010-12-21 20:27 编辑 ] |
|