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. 配置Slf4j依赖,桥接各种多个日志组件(排除commons-logging依赖的影响)

    由于各个jar组件使用的日志框架不一样,实际项目中可能会引入多个jar,通常使用的日志框架有 commons-logging log4j 若同一个项目引入多个日志组件,那么Slf4j组件会有不能捕捉到 ...

  2. Hibernate课程 初探多对多映射2-2 创建持久化类和映射文件

    生成实体类 和 cfg.xml配置 cfg.xml 参照一对多映射 实体类如下: Project 类 package com.ddwei.entity; import java.util.HashSe ...

  3. Android - 开发页面需了解的dip,sp,px知识,以及它们的转换

    工作中,时常会有任务要求开发新页面,这时一般的流程是产品经理确定要开发的页面和功能,然后设计师提供设计稿,之后由我们开发人员完成开发工作. 通常,设计师提供的设计稿尺寸标注会很详细,例如涉及到字时,字 ...

  4. win10 安装mysql zip 压缩包版

    从官网下载zip https://www.mysql.com/downloads/ 解压 D:\devtool\mysql-5.7.17-winx64\ 将  D:\devtool\mysql--wi ...

  5. Struts2_访问Web元素

    取得Map 类型的 request,session,application, HttpServletRequest,HttpSession,ServletContext的引用. 分访问 Map 类型和 ...

  6. java环境变量配置备忘录

    用鼠标右击“我的电脑”->属性->高级->环境变量系统变量->新建->变量名:JAVA_HOME 变量值:D:\Program Files\Java\jdk1.6.0_1 ...

  7. Ubuntu、Windows 、Linux集合

    一.Ubuntu/Windows双系统修复引导   首先说明:在Windows存在的前提下安装Ubuntu(或者Ubuntu系列)是不需要修复引导的.因为grub会自动搜索存在硬盘中的系统.   而在 ...

  8. Centos 6/RHEL disable the IPv6 module.

    http://minimallinux.blogspot.com/2013/07/centos-6rhel-disable-ipv6-module.html IPv6 was introduced t ...

  9. 笨办法学Python(二十八)

    习题 28: 布尔表达式练习 上一节你学到的逻辑组合的正式名称是“布尔逻辑表达式(boolean logic expression)”.在编程中,布尔逻辑可以说是无处不在.它们是计算机运算的基础和重要 ...

  10. C#后台unxi时间戳转换为前台JS时间的方法

    后台返回的时间是一个格式为 /Date(1530153274362)/ 的unxi时间戳前台转换代码:var matchResult = data.match(/(\d+)/);if (matchRe ...