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…nk * 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
上传者
张云聪
题目:比如这个三角形有4层,他的第一层为1.....第四层为4,T(n)=1+2+3+4;但是他不是让我们求T(n),让我们求W(n),W(n)=k*T(k+1); (k=1,2,....n);
然后输出的这三位分别是:第一位 1-t(t是多少组测试数据),第二位是 n(就是你输入的n),第三位是 W(n),(英语不好,别见怪哈~) 具体看代码实现:
#include<stdio.h>
//用来求T(n),1+2+3+...n;
int f(int n)
{
int i,ans;
ans=;
for(i=;i<=n;i++)
ans+=i;
return ans;
}
int main()
{
int t,a;
a=; //用来计1到t;
scanf("%d",&t);
while(t--)
{
int i,n,k,ans;
ans=;
k=;
scanf("%d",&n);
//用来求W(n)
for(i=;i<n;i++)
{
ans+=(k*f(k+));
k++;
}
printf("%d %d %d\n",a++,n,ans);
}
return ;
}

Triangular Sums 南阳acm122的更多相关文章

  1. Triangular Sums

    描述 The nth Triangular number, T(n) = 1 + … + n, is the sum of the first n integers. It is the number ...

  2. POJ 3086 Triangular Sums (ZOJ 2773)

    http://poj.org/problem?id=3086 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1773 让你计算两 ...

  3. 【南阳OJ分类之语言入门】80题题目+AC代码汇总

    小技巧:本文之前由csdn自动生成了一个目录,不必下拉一个一个去找,可通过目录标题直接定位. 本文转载自本人的csdn博客,复制过来的,排版就不弄了,欢迎转载. 声明: 题目部分皆为南阳OJ题目. 代 ...

  4. NYOJ--122--Triangular Sums

    Triangular Sums 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 The nth Triangular number, T(n) = 1 + - + n ...

  5. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  6. OJ题解记录计划

    容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001  A+B Problem First AC: 2 ...

  7. nyoj 122-Triangular Sums (数学之读懂求和公式的迭代)

    122-Triangular Sums 内存限制:64MB 时间限制:3000ms 特判: No 通过数:5 提交数:7 难度:2 题目描述: The nth Triangular number, T ...

  8. [LeetCode] Find K Pairs with Smallest Sums 找和最小的K对数字

    You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define ...

  9. UVA-11997 K Smallest Sums

    UVA - 11997 K Smallest Sums Time Limit: 1000MS   Memory Limit: Unknown   64bit IO Format: %lld & ...

随机推荐

  1. Android大牛

    张鸿洋 http://blog.csdn.net/lmj623565791/article/category/2680597 CSDN 鸿洋:http://blog.csdn.net/lmj62356 ...

  2. (二)JavaScript之[函数]与[作用域]

    3].函数 /** * 事件驱动函数. * 函数执行可重复使用的代码 * * 1.带参的函数 * 2.带返回值的函数 * 3.局部变量 * * 4.全局变量 * 在函数外的:不用var声明,未声明直接 ...

  3. oracle 递归查询(来源于网络)

    比如 a   b a   c   a   e b   b1 b   b2 c   c1 e   e1 e   e3 d   d1 指定parent=a,选出 a   b a   c   a   e b ...

  4. 微信公众平台开发——helloworld

    威信公众平台有两种模式:编辑模式 和 开发模式. 普通的功能可以通过编辑模式来搞定.开发模式具有更多的功能.让我们来使用开发模式开发helloword吧 步骤如下: 1.先注册一个公众号(https: ...

  5. python+selenium第一个脚本

    #coding=utf-8from selenium import webdriverfrom selenium.webdriver.common.keys import Keysimport tim ...

  6. union和struct的区别之处,在于内存的共享上

    首先看看union,在c++中,union可能没有多大用处,在c语言中,可能我们要借助其完成很多巧妙的设计,下面是其一个完整的定义: union UTest         {             ...

  7. react+webpack 引入字体图标

    在使用react+webpack 构建项目过程中免不了要用到字体图标,在引入过程中报错,不能识别字体图标文件中的@符,报错 Uncaught Error: Module parse failed: U ...

  8. python 的矩阵运算——numpy

    nbarray对象,就类似于C语言的数组!!! 一维数组: nbarray.array([]) 二维数组: nbarray.array([[],[]]) 数组大小: .shape 修改数组的排列: . ...

  9. python_5_password

    #1.python2中raw_input与python3中的input是相同的,python2中也有input但是别用(不好用,忘记它) #密码是明文的 username=input("us ...

  10. 关于css 中position使用的浅谈

    在css中有一种属性position.在W3C上我们可以找到他又一下几种属性:absolute.fixed.relative.static.inherit.但是position的使用却并不是简简单单的 ...