| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2008 人关注过本帖
标题:为什么会进入死循环,哪里出了问题?
只看楼主 加入收藏
tlliqi
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:204
帖 子:15453
专家分:65956
注 册:2006-4-27
收藏
得分:0 
以下是引用hu9jj在2014-12-4 12:03:58的发言:

计算机性能指标竞赛
俺那老机子估计得好几天跑8出来,8敢试哪
2014-12-04 12:30
yeyeyeyue
Rank: 1
等 级:新手上路
帖 子:65
专家分:0
注 册:2014-11-26
收藏
得分:0 
以下是引用wp231957在2014-12-4 10:20:46的发言:

果断break

这可如何是好。。
2014-12-04 13:43
mxbing1984
Rank: 7Rank: 7Rank: 7
来 自:贵州道真
等 级:贵宾
威 望:37
帖 子:73
专家分:342
注 册:2014-8-8
收藏
得分:0 
回复 28 楼 吹水佬
我错了,是400多亿,1000亿结果是25.9了,我现在已经计算到24.3了,已耗时1个小时,当然代码不是这个循环

天再高,踮起脚尖就能更接近阳光
2014-12-04 15:32
Tiger5392
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:88
帖 子:2775
专家分:2237
注 册:2006-5-17
收藏
得分:0 
不需要400多亿,149亿不到,时间3.5-5小时,没事干可以试试看

感言:学以致用。 博客:http://www./blog/user14/65009/index.shtml email:Tiger5392@
2014-12-04 16:15
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:2 
调和级数级数是发散的

授人以渔,不授人以鱼。
2014-12-04 16:37
mxbing1984
Rank: 7Rank: 7Rank: 7
来 自:贵州道真
等 级:贵宾
威 望:37
帖 子:73
专家分:342
注 册:2014-8-8
收藏
得分:0 
回复 34 楼 Tiger5392
要啦,我的计算到36580622336了,才24.9,耗时2个多钟

天再高,踮起脚尖就能更接近阳光
2014-12-04 16:49
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
当n越来越大时,调和级数的项变得越来越小,然而,慢慢地——非常慢慢地——它的和将增大并超过任何一个有限值。调 和级数的这种特性使一代又一代的数学家困惑并为之着迷。下面的数字将有助于我们更好地理解这个级数。这个级数的前1000项相加约为7.485;前100 万项相加约为14.357;前10亿项相加约为21;前一万亿项相加约为28,等等。更有学者估计过,为了使调和级数的和等于100,必须把10的43次 方项加起来,如果我们试图在一个很长的纸带上写下这个级数,知道它的和超过100,即使每一项只占1mm长的纸带,也必须使用10的43次方mm长的纸 带,这大约为10的25次方光年,但是宇宙已知尺寸估计只有10的12次方光年。

调和级数是发散的,这是一个令人困惑的事情,事实上调和级数令人不耐烦地慢慢向无穷大靠近,我们可以很容易的看到这 个事实,因为S2n-Sn>1/2,而调和级数的第一项是1,也就是说调和级数的和要想达到51那么它需要有2的100次方那个多项才可以。而2的 100次方这个项是一个大到我们能够处理范围以外的数字,在计算机元科学领域,这属于一个不可解的数。

授人以渔,不授人以鱼。
2014-12-04 17:47
mxbing1984
Rank: 7Rank: 7Rank: 7
来 自:贵州道真
等 级:贵宾
威 望:37
帖 子:73
专家分:342
注 册:2014-8-8
收藏
得分:0 
--我的结果出来啦
--我是在sql server中先见一个表,向里面插入2097152条记录
--然后按步长设为2097152,一直加到S>=24.99999
--剩下的按步长设为1,一直加到S>=25
--总耗时约160分钟
--结果N=40427833528时S=25.0000000000139
--按公式计算∑1/n→C+ln(n)
--结果为N=40427833597时S=25.0000000000184
--误差-69

Create Table T
(
  A int identity(1,1) primary key,
  B int
)
GO
 
--插入2097152记录
Insert Into T(B) Values(null)
 
Declare @I Int=1
While @I<=21
Begin
    Insert Into T(B)
        Select B From T
    Set @I=@I+1
End

--开始计算,步长设置为2097152
Declare @T Float=0
Declare @S Float=0
While @S<=24.99999
Begin
    Select @S=@S+sum(1.0/(@T+A)) From T  
    Set @T=@T+2097152
End

select @T As T,  @S As S
--以上大约160分钟,到此@T=40424701952,@S=24.9999225344321
--开始计算,步长设置为1
While 1=1
Begin
    Set @S=@S+1.0/@T
    If @S>=25.0
        Break
    Else
        Set @T=@T+1  
End
Select @T As T, @S As S
--以上2秒,到此@T=40427833528,@S=25.0000000000139

Select log(40427833597)+0.57721566490153286060651209
--结果为25.0000000000184,误差40427833528-40427833597=-69

天再高,踮起脚尖就能更接近阳光
2014-12-04 17:54
Tiger5392
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:88
帖 子:2775
专家分:2237
注 册:2006-5-17
收藏
得分:0 
调和级数大于25的最小n值,真的不是400亿,真的只有149亿不到。用Σ1/n=log(n)+C来计算,是一个很不精确的结果。

感言:学以致用。 博客:http://www./blog/user14/65009/index.shtml email:Tiger5392@
2014-12-04 21:26
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10607
专家分:43186
注 册:2014-5-20
收藏
得分:0 
Σ1/n=log(n)+C 的精度在于C(欧拉常数),能用到几多位:
0.577215,66490,15328,60606,51209,00824,02431,04215,93359,39923,59880,57672,34
884,86772,67776,64670,93694,70632,91746,74951,46314,47249,80708,24809,60504,0144
8,65428,36224,17399,76449,23536,25350,03337,42937,33773,76739,42792,59525,82470,
94916,00873,52039,48165,67085,32331,51776,61152,86211,99501,50798,47937,45085,70
574,00299,21354,78614,66940,29604,32542,15190,58775,53526,73313,99254,01296,7420
5,13754,13954,91116,85102,80798,42348,77587,20503,84310,93997,36137,25530,60889,
33126,76001,72479,53783,67592,71351,57722,61027,34929,13940,79843,01034,17771,77
808,81549,57066,10750,10161,91663,34015,22789,35867,96549,72520,36212,87922,6555
9,53669,62817,63887,92726,80132,43101,04765,05963,70394,73949,57638,90657,29679,
29601,00901,51251,95950,92224,35014,09349,87122,82479,49747,19564,69763,18506,67
612,90638,11051,82419,74448,67836,38086,17494,55169,89279,23018,77391,07294,5781
5,54316,00500,21828,44096,05377,24342,03285,47836,70151,77394,39870,03023,70339,
51832,86900,01558,19398,80427,07411,54222,78197,16523,01107,35658,33967,34871,76
504,91941,81230,00406,54693,14299,92977,79569,30310,05030,86303,41856,98032,3108
3,69164,00258,92970,89098,54868,25777,36428,82539,54925,87362,95961,33298,57473,
93023,73438,84707,03702,84412,92016,64178,50248,73337,90805,62754,99843,45907,61
643,16710,31467,10722,37002,18107,45044,41866,47591,34803,66902,55324,58625,4422
2,53451,81387,91243,45735,01361,29778,22782,88148,94590,98638,46006,29316,94718,
87149,58752,54923,66493,52047,32436,41097,26827,61608,77595,08809,51262,08404,54
447,79922,99157,24829,25162,51278,42765,96570,83214,61029,82146,17951,95795,9095
9,22704,20898,96279,71255,36321,79488,73764,21066,06070,65982,56199,01028,80756,
12519,91375,11678,21764,36190,57058,44078,35735,01580,05607,74579,34213,14498,85
007,86415,17161,51945,65706,17043,24507,50081,68705,23078,90937,04614,30668,4817
9,16496,84254,91504,96724,31218,37838,75356,48949,50868,45410,23406,01622,50851,
55838,67234,94418,78804,40940,77010,68837,95111,30787,20234,26395,22692,09716,08
856,90838,25113,78712,83682,04911,78925,94478,48619,91185,29391,02930,99059,2552
6,69172,74468,92044,38697,11147,17457,15745,73203,93520,91223,16085,08682,75588,
90109,45168,11810,16874,97547,09693,66671,21020,63048,27165,89504,93273,14860,87
494,02070,06742,59091,82487,59621,37384,23114,42653,13502,92303,17517,22572,2162
8,32488,38112,45895,74386,23987,03757,66285,51303,31439,29995,40185,31341,41586,
21278,86480,76110,03015,21196,57800,68117,77376,35016,81838,97338,96639,86895,79
329,91456,38864,43103,70608,07817,44899,57958,32457,94189,62026,04984,10439,2250
7,86046,03625,27726,02291,96829,95860,98833,90137,87171,42269,17883,81952,98445,
60791,60519,72797,36047,59102,51099,57791,33515,79177,22515,02549,29324,63250,28
747,67794,84215,84050,75992,90401,85576,45990,18626,92677,64372,66057,11768,1336
5,59088,15548,10747,00006,23363,72528,89495,54636,97143,30120,07913,08555,26395,
95497,82302,31440,39149,74049,47468,25947,32084,61852,46058,77669,48828,79530,10
406,34917,22921,85800,87067,70690,42792,67432,84446,96851,49718,25678,09584,1654
4,91851,45753,31964,06331,19937,38215,73450,87498,83255,60888,87352,80190,19155,
08968,85546,82592,45444,52772,81730,57301,08060,61770,11363,77318,24629,24660,08
127,71621,01867,74468,49595,14281,79014,51119,48934,22883,44825,30753,11870,1860
9,76122,46231,76749,77556,41246,19838,56401,48412,35871,77249,55422,48201,61517,
65799,40806,29683,42428,90572,59473,92696,38633,83874,38054,71319,67642,92683,72
490,76087,50737,85283,70230,46865,03490,51203,42272,17436,68979,28486,29729,0889
2,67897,77032,62462,39122,61888,76530,05778,62743,60609,44436,03928,09770,81338,
36934,23550,85839,41126,70921,87344,14512,18780,32761,50509,47805,54663,00586,84
556,31524,54605,31511,32528,18891,07923,14913,11032,34430,24509,33450,00307,6558
6,48742,22971,77003,31784,53915,05669,40159,98849,29160,91140,02948,69020,88485,
38169,70095,51566,34705,54452,21764,03586,29398,28658,13123,87013,25358,80062,56
866,26926,99776,77377,30683,22690,09160,85104,51500,22610,71802,55465,92849,3894
9,27759,58975,40761,55993,37826,48241,97950,64186,81437,88171,85088,54080,36799,
63142,39540,09196,43887,50078,90000,06279,97942,80988,63729,92591,97776,50404,09
922,03794,04276,16817,83715,66865,30669,39830,91652,43227,05955,30417,66736,6401
1,67929,59012,93053,74497,18308,00427,58486,35083,80804,24667,35093,55983,23241,
16969,21486,06498,92763,62443,29588,54873,78970,14897,13343,53844,80028,90466,65
090,28453,76896,22398,30488,14062,73054,08795,91189,67057,49385,44324,78691,4808
5,33770,26406,77580,81275,45873,11176,36478,78743,07392,06642,01125,13527,27499,
61754,50530,85582,35668,30683,22917,67667,70410,35231,53503,25101,24656,38615,67
064,49847,13269,59693,30167,86613,83333,33441,65790,06058,67497,10364,68951,7456
9,59718,15537,64078,37765,01842,78345,99184,20159,95431,44904,77255,52306,14767,
01659,93416,39066,09120,54005,32215,89020,91340,80278,22515,33852,89951,16654,52
245,86918,59936,71220,13215,01448,01424,23098,62546,04488,67256,93431,48870,4915
9,30446,40189,16450,20224,05495,38629,18475,86293,07788,93506,43771,59660,69096,
04681,24370,23054,65703,16067,99925,87166,67524,72194,09777,98018,63626,25633,58
252,62794,22393,25486,01326,93530,70138,89374,36923,84287,89385,12764,74085,6548
6,50281,56306,77404,42203,06440,37568,26309,10291,75145,72234,44105,03693,17711,
45217,08889,07446,41604,86887,01083,86231,14261,28441,42596,09563,70400,61920,05
793,35034,15524,26240,26206,46569,35430,61258,52658,34521,92121,49777,18780,6958
6,60851,63349,22104,83673,79945,92594,34037,95600,02192,78541,83794,17760,20336,
55946,73078,87983,80848,16314,67824,14923,54649,14887,66833,68407,49289,38652,81
863,04858,98203,54818,62438,38481,75997,63584,90751,80791,48063,49439,16284,7054
8,22007,54945,34898,61338,27235,73092,21900,30740,09680,03376,66844,93250,55676,
54937,53031,81125,16410,55249,23840,77645,14984,23957,62012,78155,23229,44928,85
455,78538,20248,91894,24418,57095,91955,82081,00071,57838,40396,27479,98581,7880
8,88865,71683,06994,36060,73599,04210,68511,42791,31696,99596,79230,08289,9......
2014-12-04 22:25
快速回复:为什么会进入死循环,哪里出了问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020488 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved