|
Q39 If p is the perimeter of a right angle triangle, {a, b, c}, which value, for p ≤ 1000, has the most solutions?
If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
{20,48,52}, {24,45,51}, {30,40,50}
For which value of p ≤ 1000, is the number of solutions maximised?
这个和Q9类似。
直接暴力没多少难度。
with targ as (select 1000 arg from dual)
,t as (select rownum n from targ connect by rownum<=arg/2) --a/b/c都不超过500
,t1 as (select ta.n a, tb.n b, round(sqrt(ta.n*ta.n+tb.n*tb.n)) c , ta.n+tb.n+ round(sqrt(ta.n*ta.n+tb.n*tb.n)) p
from t ta, t tb where round(sqrt(ta.n*ta.n+tb.n*tb.n),8) =round(sqrt(ta.n*ta.n+tb.n*tb.n)))
,t2 as (select p, count(*) cnt from t1,targ
where a<=p/3 and b>=a and b<c and c>=p/3
and p < arg group by p)
select * from t2 where cnt = (select max(cnt) from t2)
P CNT
---------- ----------
840 8
Executed in 0.704 seconds |
|