日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

Triangular Sums http://acm.nyist.net/JudgeOnline/problem.php?pid=122

發布時間:2025/3/19 php 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Triangular Sums http://acm.nyist.net/JudgeOnline/problem.php?pid=122 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

Triangular Sums

時間限制:3000 ms ?|? 內存限制:65535 KB 難度:2 描述

The?nth?Triangular?number,?T(n) = 1 + … +?n, is the sum of the first?n?integers. It is the number of points in a triangular array with?n?points on side. For example?T(4):

X
X X
X X X
X X X X

Write a program to compute the weighted sum of triangular numbers:

W(n) =?SUM[k?= 1…n;?k?*?T(k?+ 1)]

輸入
The first line of input contains a single integer N, (1 ≤ N ≤ 1000) which is the number of datasets that follow.

Each dataset consists of a single line of input containing a single integer n, (1 ≤ n ≤300), which is the number of points on a side of the triangle.
輸出
For each dataset, output on a single line the dataset number (1 through N), a blank, the value of n for the dataset, a blank, and the weighted sum ,W(n), of triangular numbers for n.
樣例輸入
4 3 4 5 10
樣例輸出
1 3 45 2 4 105 3 5 210 4 10 2145
來源
Greater New York 2006
#include<stdio.h> int main() {int i,n;scanf("%d",&n);for(i=1;i<=n;i++){int k,j,m;long int toal=0,sum=1;scanf("%d",&m);for(j=1;j<=m;j++){sum+=j+1;toal=toal+j*sum;}printf("%d %d %ld\n",i,m,toal);}return 0; }


一看題估計你會蒙了,但是一看代碼估計你會笑,其實此題不難,難的是理解不了題意。題意是給你一個數n,然后求出前n+1項和T(n+1),然后計算n*T(n+1);輸出時注意格式就行了。

轉載于:https://www.cnblogs.com/wangyouxuan/p/3248825.html

總結

以上是生活随笔為你收集整理的Triangular Sums http://acm.nyist.net/JudgeOnline/problem.php?pid=122的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。