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

#include<stdio.h>
#define T(k) (k)*(k+1)/2
int main()
{
    int N;
    ;
    scanf("%d",&N);
    while(N--){
        int n;
        ;
        scanf("%d",&n);
        ;i<=n;i++)num +=i*T(i+);
        k++;
        printf("%d %d %d\n",k,n,num);
    }
    ;
}

NYOJ--122--Triangular Sums的更多相关文章

  1. Triangular Sums 南阳acm122

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

  2. Triangular Sums

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

  3. POJ 3086 Triangular Sums (ZOJ 2773)

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

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

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

  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. 32-语言入门-32-Triangular Sums

    题目地址: http://acm.nyist.net/JudgeOnline/problem.php?pid=122    描述The nth Triangular number, T(n) = 1 ...

  9. CF1303G Sum of Prefix Sums

    点分治+李超树 因为题目要求的是树上所有路径,所以用点分治维护 因为在点分治的过程中相当于将树上经过当前$root$的一条路径分成了两段 那么先考虑如何计算两个数组合并后的答案 记数组$a$,$b$, ...

随机推荐

  1. 根据list得到list中的最大值最小值

    List ll = new ArrayList(); ll.add(new BigDecimal(1)); ll.add(new BigDecimal(4.99)); ll.add(new BigDe ...

  2. 【LeetCode】119. Pascal's Triangle II

    题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [ ...

  3. 【LeetCode】67. Add Binary

    题目: Given two binary strings, return their sum (also a binary string). For example,a = "11" ...

  4. Ext template 的使用

    Ext template 的使用 Ext.define('app.view.MyDataView', { extend: 'Ext.panel.Panel', xtype: 'myDataView', ...

  5. Javacript 学习笔记

    一.初探 javacript 学习无法是围绕着对象和属性两个方面来兜圈子,万变不离其宗. 在js中,能点出来的,或者中括号里面的必然是属性(方法).数组除外. 对象调用属性! 对象调用属性! 对象调用 ...

  6. 最全的CSS浏览器兼容问题(转至http://68design.net/Web-Guide/HTMLCSS/37154-1.html)

    最全的CSS浏览器兼容问题   CSS对浏览器的兼容性有时让人很头疼,或许当你了解当中的技巧跟原理,就会觉得也不是难事,从网上收集了IE7,6与Fireofx的兼容性处理方法并整理了一下.对于web2 ...

  7. Linux进程/内核模型

    内核必须实现一组服务和相应的接口,应用程序则可以使用这些接口,而不是直接与硬件打交道. Linux内核主要由以下5个子系统组成:进程调度.内存管理.虚拟文件系统.进程间通信以及设备驱动. 在这个组成中 ...

  8. Educational Codeforces Round 21 A-E题题解

    A题      ............太水就不说了,贴下代码 #include<string> #include<iostream> #include<cstring& ...

  9. java for循环

    publicclass Test2 {     staticboolean foo(char c) {        System.out.print(c);        returntrue;   ...

  10. MySQL-FAQ

    1.ERROR 1130: Host 'xxx' is not allowed to connect to this MySQL server远程连接mysql服务器报上述错误.解决方法:1.改表法. ...