推介:| 英語課程 | Causeway Bay order food | 職業英語 | 化妝課程 | Wedding Photography | 天窗卷布更換維修 |

發新話題
打印

高手快來!!!VB PERFECT NUMBER(完整數)

to accomplish a goal, there's alway a stupid way and a much clever way, here's the stupid way:

as stated in the question, a perfect number is the sum of its factors including 1. you want fo find all perfect numbers between 1 and 1000.

1. firstly, you know this has to be done in a loop from 1 to 1000.
2. for each number between 1 to 1000, find its factors and compare the sum with the value
    (hint: to find one's factors, devide the number by all nubers smaller than it, factors are ones with MOD = 0, if you dont know what MOD is, google it
      e.g. 10:
10/1 MOD 0 (Factor),
10/2 MOD 0 (Factor),
10/3 MOD 1 (nop),
10/4 MOD 2 (nop) ,
10/5 MOD 0 (Factor) ,
10/6 MOD 4 (nop) ,
10/7 MOD 3 (nop) ,
10/8 MOD 2 (nop) ,
10/9 MOD 1 (nop)

therefore factors of 10 are 1, 2, 5, the sum is 8 which does not equal to 10, so 10 is not a perfect number.

makes sense?

[ 本帖最後由 fsnow 於 2007-10-24 23:00 編輯 ]

TOP

發新話題


重要聲明:本討論區是以即時上載留言的方式運作,本網站對所有留言的真實性、完整性及立場等,不負任何法律責任。而一切留言之言論只代表留言者個人意見,並非本網站之立場,用戶不應信賴內容,並應自行判斷內容之真實性。於有關情形下,用戶應尋求專業意見(如涉及醫療、法律或投資等問題)。由於本討論區受到「即時上載留言」運作方式所規限,故不能完全監察所有留言,若讀者發現有留言出現問題,請聯絡我們。本討論區有權刪除任何留言及拒絕任何人士上載留言,同時亦有不刪除留言的權利。切勿撰寫粗言穢語、誹謗、渲染色情暴力或人身攻擊的言論,敬請自律。本網站保留一切法律權利。


Copyright 1997- Xocat. All Right Reserved.