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

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

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

[其他] Project Euler - 006 [復(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)] [報(bào)告]
發(fā)表于 2015-09-27 11:42 |只看該作者 |倒序?yàn)g覽
Problem 006:
The sum of the squares of the first ten natural numbers is,
1^2 + 2^2 + ... + 10^2 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)^2 = 55^2 = 3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

問題6:
前十個(gè)自然數(shù)的平方和:1^2 + 2^2 + ... + 10^2 = 385
前十個(gè)自然數(shù)的和的平方是:(1 + 2 + ... + 10) ^ 2 = 55^2 = 3025
所以兩者之差是:3025-385=2640
現(xiàn)在,試求出前一百個(gè)自然數(shù)的和的平方與平方和的差。

代碼:

  1. package main

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

  5. func SumOfArithmeticSequence(min, max, step int) int {
  6.         return (min + max) * ((max - min + 1) / step) / 2
  7. }

  8. func SumOfSquareSequence(min, max int) int {
  9.         result := 0
  10.         for index := min; index <= max; index++ {
  11.                 result = result + index * index
  12.         }
  13.         return result
  14. }

  15. func Problem006(maxNumber int) int {
  16.     square := SumOfSquareSequence(1, maxNumber)   
  17.         sequence := SumOfArithmeticSequence(1, maxNumber, 1)
  18.         return sequence * sequence - square
  19. }

  20. func main() {
  21.         fmt.Println("Problem 006 result: ", Problem006(100))
  22. }
復(fù)制代碼

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2015-10-07 15:03 |只看該作者
回復(fù) 1# icymirror


    lz沒有題目005呀

論壇徽章:
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
3 [報(bào)告]
發(fā)表于 2015-10-08 08:17 |只看該作者
回復(fù) 2# ba_du_co
有的,但是之前好像都被自動(dòng)當(dāng)作重復(fù)發(fā)帖屏蔽了。

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2015-10-09 11:43 |只看該作者
回復(fù) 3# icymirror


能重來一發(fā)?
謝謝

您需要登錄后才可以回帖 登錄 | 注冊(cè)

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

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP