|
本帖最后由 tree_new_bee 于 2012-2-11 21:52 编辑
基本照抄过来Q76的代码,试了试:- create or replace procedure Q78(arg number default 100) is
- type t_nlist is table of number index by pls_integer;
- type t_nlistlist is table of t_nlist index by pls_integer;
- nlist t_nlistlist;
- sm number;
- begin
- for i in 1..arg loop
- nlist(1)(i) := 1;
- nlist(i)(1) := 1;
- end loop;
-
- for i in 2..arg loop
- for j in 2..arg loop
- if j<i then
- nlist(i)(j) := nlist(i-j)(j) + nlist(i)(j-1);
- elsif j=i then
- nlist(i)(j) := nlist(i)(j-1) + 1;
- elsif j>i then
- nlist(i)(j) :=nlist(i)(j-1);
- end if;
- end loop;
- if nlist(i)(i)mod 1e6 = 0 then
- dbms_output.put_line('result=' || i || ', p(i)=' || nlist(i)(i));
- return;
- end if;
- end loop;
- dbms_output.put_line('no result! try big arg.');
- end Q78;
复制代码 参数试到2000时,出来了结果:
SQL> exec q78(2000)
result=1759, p(i)=4280750559177948266124532321685590709000000
PL/SQL procedure successfully completed
Executed in 1.232 seconds
但是, 别急。 填进去这个答案,是错的。
为什么呢? 看看得到的 p(i)=4280750559177948266124532321685590709000000, 6个0前面的位数是38位, 正好是oracle number的精度。
所以这个数能被1000000整除是假的。
并且, 先不说大数问题(有大数包, 大数不是问题), 注意参数为2000已经要1秒多了(在100-200时,速度0.0x秒), 如果结果是上万的, 那么也许就很难出来了。
|
|