|
第二部, 根据上面的结果去找这些底形成的唯一幂。
推导一下:
假设两个数分别为x1^y1=x2^y2, 这两个数重复的话是因为x1与x2共同是某个数的幂, 设这个数为x0, x1=x0^n1, x2=x0^n2
则上式变为 (x0^n1)^y1 = (x0^n2)y2
即x0^(n1*y1) = x0^(n2*y2)
所以n1*y1 = n2*y2
以具体例子来说: 对于4^6 和8^4, 4=2^2, 8=2^3, 而2*6 = 3*4, 所以这两个数相等。
这样,利用第一步的成果,就容易得到这18个数的结果数量, 加上8019即最后的结果。
with t as (select rownum+1 n from dual connect by rownum<100)
,t1 as (select t1.n n1, t2.n n2, round(log(t2.n, t1.n)) m from t t1, t t2
where t2.n<=10
and log(t2.n, t1.n) >1 and round(log(t2.n, t1.n),0) = round(log(t2.n, t1.n),3)
)
,t2 as (select n1, n2, m from t1 where n2 not in(select n1 from t1)
union select n2 n1, n2 n2, 1 from t1 where n2 not in(select n1 from t1))
--select * from t2
,t3 as (select n1, n2, m, m*n p from t2, t)
select count(*)+81*99 total from (select distinct n2, p from t3);
TOTAL
----------
9183
Executed in 0.25 seconds |
|