Triangular Sums
描述
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
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 2145import java.text.NumberFormat;
import java.util.Arrays;
import java.util.Scanner; public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int T;
int n;
int k;
int i;
int temp;
int sum;
int time=1; T=scanner.nextInt();
while(true){
if(T==0)
break;
T--; n=scanner.nextInt(); sum=0;
for(k=1;k<=n;k++){
temp=0;
for(i=1;i<=k+1;i++)
temp+=i; sum+=k*temp;
}
System.out.println(time+" "+n+" "+sum);
time++;
}
}
}
Triangular Sums的更多相关文章
- Triangular Sums 南阳acm122
Triangular Sums 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 The nth Triangular number, T(n) = 1 + … + n ...
- POJ 3086 Triangular Sums (ZOJ 2773)
http://poj.org/problem?id=3086 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1773 让你计算两 ...
- NYOJ--122--Triangular Sums
Triangular Sums 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 The nth Triangular number, T(n) = 1 + - + n ...
- 【南阳OJ分类之语言入门】80题题目+AC代码汇总
小技巧:本文之前由csdn自动生成了一个目录,不必下拉一个一个去找,可通过目录标题直接定位. 本文转载自本人的csdn博客,复制过来的,排版就不弄了,欢迎转载. 声明: 题目部分皆为南阳OJ题目. 代 ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- OJ题解记录计划
容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001 A+B Problem First AC: 2 ...
- nyoj 122-Triangular Sums (数学之读懂求和公式的迭代)
122-Triangular Sums 内存限制:64MB 时间限制:3000ms 特判: No 通过数:5 提交数:7 难度:2 题目描述: The nth Triangular number, T ...
- [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 ...
- UVA-11997 K Smallest Sums
UVA - 11997 K Smallest Sums Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & ...
随机推荐
- Cocos2d-x 关于Android.mk 自动读入CPP
***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...
- 3.VS2010C++相关文件说明
stdafx.h说明:stdafx的英文全称为:Standard Application Framework Extensions(标准应用程序框架的扩展).所谓头文件预编译,就是把一个工程(Proj ...
- POJ 1584 A Round Peg in a Ground Hole(判断凸多边形,点到线段距离,点在多边形内)
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4438 Acc ...
- Ubuntu 14.04 LTS中怎样解决系统设置残缺的问题
iBus卸载之后,系统设置会缺失,是Ubuntu 14.04和iBus之间的关系引起的,但是如果直接安装 sudo apt-get install ubuntu-desktop 这个会把amazon广 ...
- A - Oulipo
A - Oulipo Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit S ...
- 自定义滚动控件(Pagecontrol)
// // MyPageCorol.h // lejiahui // // Created by iOS开发 on 16/4/10. // Copyright © 2016年 zhongmingwuy ...
- 圣杯VS双飞翼
双飞翼: <!DOCTYPE html> <html> <head> <title>推荐封面</title> <meta name=& ...
- 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.4 Edit修改用户信息]
3.4 Edit修改用户信息 我们用FormCollection简化了表单提交,非常方便的进行用户信息修改. [HttpPost, Authorize] public async Task<Ac ...
- Java 关于 == 和 equal()的区别
因为用new创建了两个对象,所以a和b指向两个不同的内存地址,所以返回false equal()是object的方法,所以只适用于对象,不使用于基本类型.不过equal()默认是用“==”比较两个对象 ...
- document.compatMode(判断当前浏览器采用的渲染方式)
转载自:http://www.cnblogs.com/fullhouse/archive/2012/01/17/2324706.html IE对盒模型的渲染在 Standards Mode和Quirk ...