亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 4273 | 回復(fù): 2
打印 上一主題 下一主題

[其他] Project Euler - 001 [復(fù)制鏈接]

論壇徽章:
4
白羊座
日期:2013-11-05 10:26:09冥斗士
日期:2015-11-17 14:19:55白銀圣斗士
日期:2015-11-17 15:13:0815-16賽季CBA聯(lián)賽之新疆
日期:2016-04-01 09:10:58
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2015-09-24 23:05 |只看該作者 |倒序瀏覽
本帖最后由 icymirror 于 2015-09-26 17:34 編輯

最近沒有那么忙,開始學(xué)習(xí)golang,有空就拿Project Euler上的題目來練手吧。

Problem 1.
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.

問題1:
如果我們把10以內(nèi)的3或5的倍數(shù)列出來,我們會得到:3, 5, 6和9。這些數(shù)之和是23。
現(xiàn)在,找出1000以內(nèi)的3或5的倍數(shù)的數(shù)字之和。

method 1
  1. package main

  2. import (
  3.         "fmt"
  4. )

  5. func Problem001_basic(scope, factor1, factor2 int) int {
  6.         sum := 0

  7.         for index := 0; index <= scope; index += factor1 {
  8.                 sum = sum + index
  9.         }
  10.        
  11.         for index := 0; index <= scope; index += factor2 {
  12.                 sum = sum + index
  13.         }
  14.        
  15.         for index := 0; index <= scope; index += factor1 * factor2 {
  16.                 sum = sum - index
  17.         }
  18.        
  19.         return sum
  20. }

  21. func Problem001_improve(scope, factor1, factor2 int) int {
  22.         sum := (factor1 + scope / factor1 * factor1) * (scope / factor1) / 2
  23.         sum = sum + (factor2 + scope / factor2 * factor2) * (scope / factor2) / 2
  24.         factor3 := factor1 * factor2
  25.         sum = sum -  (factor3 + scope / factor3 * factor3) * (scope / factor3) / 2
  26.         return sum
  27. }

  28. func main() {
  29.         fmt.Println("Problem 001 result: ", Problem001_basic(1000, 3, 5))
  30.         fmt.Println("Problem 001 result: ", Problem001_improve(1000, 3, 5))
  31. }
復(fù)制代碼

論壇徽章:
0
2 [報告]
發(fā)表于 2015-10-09 14:42 |只看該作者
本帖最后由 ba_du_co 于 2015-10-09 14:45 編輯

拿來練練手。
233168
  1. #!perl6
  2. say [+] (^1000).grep: * %% (3|5);
復(fù)制代碼

求職 : 機(jī)器學(xué)習(xí)
論壇徽章:
79
2015年亞洲杯紀(jì)念徽章
日期:2015-05-06 19:18:572015七夕節(jié)徽章
日期:2015-08-21 11:06:172015亞冠之阿爾納斯?fàn)?日期:2015-09-07 09:30:232015亞冠之薩濟(jì)拖拉機(jī)
日期:2015-10-21 08:26:3915-16賽季CBA聯(lián)賽之浙江
日期:2015-12-30 09:59:1815-16賽季CBA聯(lián)賽之浙江
日期:2016-01-10 12:35:21技術(shù)圖書徽章
日期:2016-01-15 11:07:2015-16賽季CBA聯(lián)賽之新疆
日期:2016-02-24 13:46:0215-16賽季CBA聯(lián)賽之吉林
日期:2016-06-26 01:07:172015-2016NBA季后賽紀(jì)念章
日期:2016-06-28 17:44:45黑曼巴
日期:2016-06-28 17:44:4515-16賽季CBA聯(lián)賽之浙江
日期:2017-07-18 13:41:54
3 [報告]
發(fā)表于 2016-04-21 15:45 |只看該作者
結(jié)果是 234168吧  !回復(fù) 2# ba_du_co


   
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP