|
原帖由 lastwinner 于 2010-11-7 13:19 发表 ![]()
我也转个简单的题:
26、 Find the value of d < 1000 for which 1/d contains the longest recurring cycle.
A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given:
1/2 = 0.5
1/3 = 0.(3)
1/4 = 0.25
1/5 = 0.2
1/6 = 0.1(6)
1/7 = 0.(142857)
1/8 = 0.125
1/9 = 0.(1)
1/10 = 0.1
Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle.
Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
————————————————————————————————————————
在d小于1000的数中,找出1/d的循环部分最长的d。
比如
1/2 = 0.5
1/3 = 0.(3)
1/4 = 0.25
1/5 = 0.2
1/6 = 0.1(6)
1/7 = 0.(142857)
1/8 = 0.125
1/9 = 0.(1)
1/10 = 0.1
0.1(6) 表示 0.166666..., 同时也说明其只包含1位数字循环. 也很容易看出1/7有6位数字循环,是2~10里面循环部分最长的.
--利用1/i的极限等于999...9/(i*10^n)的原理
set serverout on
declare
max1 number:=1;
pos number:=1;
mod1 number:=1;
mod2 number:=1;
str1 varchar2(4000):='0.';
begin
for i in 980..999 loop
str1:='0.';--||lpad('0',length(i)-1,'0');
mod1:=power(10,length(i));
mod2:=power(10,length(i))-1;
for j in 1..999 loop
mod1:=mod(mod1*power(10,length(i)),i);
str1:=str1||substr(to_char(trunc(mod2/i)+power(10,length(i))),2);
mod2:=mod(mod2,i);
if mod1=0 then
--dbms_output.put_line('有限小数i=1/'||i);
goto exit1; /*有限小数*/
end if;
if mod2=0 then
pos:=case when (j*length(i))>max1 then i else pos end;
max1:=case when (j*length(i))>max1 then (j*length(i)) else max1 end;
dbms_output.put_line('循环小数i=1/'||i||',长度='||(j*length(i))||',str=('||substr(str1,1,200)||')');
goto exit1; /*循环小数循环节*/
end if;
mod2:=mod2*power(10,length(i))+power(10,length(i))-1;
end loop;
<<exit1>>
NULL;
end loop;
dbms_output.put_line('最长i='||pos||',长度='||max1);
end;
/
循环小数i=1/981,长度=108,str=(0.0010193679918450560652395514780835881753312945973496432212028542303771661569826707441386340468909276
24872579)
循环小数i=1/983,长度=2946,str=(0.001017293997965412004069175991861648016276703967446592065106815869786368260427263479145473041709053
916581892166836215666327568667344862665310274669379450661241098677517802644964394710071210579857578)
循环小数i=1/987,长度=138,str=(0.0010131712259371833839918946301925025329280648429584599797365754812563323201621073961499493414387031
40830800405268490374873353596757852077)
循环小数i=1/989,长度=462,str=(0.0010111223458038422649140546006066734074823053589484327603640040444893832153690596562184024266936299
29221435793731041456016177957532861476238624873609706774519716885743174924165824064711830131445904)
循环小数i=1/991,长度=495,str=(0.0010090817356205852674066599394550958627648839556004036326942482341069626639757820383451059535822401
61453077699293642785065590312815338042381432896064581231079717457114026236125126135216952573158425)
循环小数i=1/993,长度=330,str=(0.0010070493454179254783484390735146022155085599194360523665659617321248741188318227593152064451158106
74723061430010070493454179254783484390735146022155085599194360523665659617321248741188318227593152)
循环小数i=1/997,长度=498,str=(0.0010030090270812437311935807422266800401203610832497492477432296890672016048144433299899699097291875
62688064192577733199598796389167502507522567703109327983951855566700100300902708124373119358074222)
循环小数i=1/999,长度=3,str=(0.001)
最长i=983,长度=2946
[ 本帖最后由 〇〇 于 2010-11-8 01:11 编辑 ] |
|