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 & ...
随机推荐
- <一道题>abc+cba=1333,求满足条件的abc的值,隐含条件a!=0,c!=0
这类东西,无非就是穷举法.见下面代码: #include <stdio.h> #include <stdlib.h> /* *abc + cba = 1333 * *a = ? ...
- WinForm控件使用文章收藏整理完成
对C# WinForm开发系列收集的控件使用方面进行整理, 加入了一些文章, 不断补充充实, 完善这方面. 基础 - 常用控件 C# WinForm开发系列 - CheckBox/Button/Lab ...
- Windows7部署WordPress傻瓜式教程(IIS7.5+MySQL+PHP+WordPress)
http://www.cnblogs.com/vengen/archive/2010/01/01/WordPressInstall.html
- MVC路由中routes.IgnoreRoute("{resource}.axd/{*pathInfo}") 到底什么意思!
转自:http://blog.csdn.net/lvjin110/article/details/24638913 参考(1) http://www.cnblogs.com/flyfish2012/a ...
- 跟SAP系统集成的Android应用
首先吐槽一点,这是我的第一个Android应用,很糙. 这个应用适合于上了SAP系统的企业内部使用,并且限于制造型MTO模式,需要针对生产订单报工操作的场景,因为此应用主要的一个目的,就是用来方便报工 ...
- php涉及数据库操作时响应很慢。
症状描述: 网站是php开发的,大部分页面响应很慢. 本地开发时响应速度很快,但是部署到生产环境后大部分响应很慢. 通过谷歌浏览调试发现PHP页面加载很慢,有个别的php请求的响应时间甚至超过10秒, ...
- CXF 与Spring整合配置
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java ...
- github命令
git push origin master //把本地源码库push到Github上 git pull origin master //从Github上pull到本地源码库
- Java是如何管理内存的?
本文转自CSDN用户Kevin涂腾飞的文章java内存管理机制:http://blog.csdn.net/tutngfei1129287460/article/details/7383480 JAVA ...
- Queue and Message
#ifndef __QUEUE_H__ #define __QUEUE_H__ #include <stdint.h> #include <stdlib.h> #include ...