hdoj 1977 Consecutive sum II

Consecutive sum II

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2523    Accepted Submission(s):
1219

Problem Description

Consecutive sum come again. Are you ready? Go
~~
1    = 0 + 1
2+3+4    = 1 + 8
5+6+7+8+9  = 8 + 27

You can
see the consecutive sum can be representing like that. The nth line will have
2*n+1 consecutive numbers on the left, the first number on the right equal with
the second number in last line, and the sum of left numbers equal with two
number’s sum on the right.
Your task is that tell me the right numbers in the
nth line.

Input

The first integer is T, and T lines will
follow.
Each line will contain an integer N (0 <= N <=
2100000).

Output

For each case, output the right numbers in the Nth
line.
All answer in the range of signed 64-bits integer.

Sample Input

3

0

1

2

Sample Output

0 1

1 8

8 27

找规律

#include<stdio.h>
#include<string.h>
int main()
{
	long long m,n;
	scanf("%lld",&n);
	while(n--)
	{
		scanf("%lld",&m);
		printf("%lld %lld\n",m*m*m,(m+1)*(m+1)*(m+1));
	}
	return 0;
}

  

时间: 2024-10-20 09:56:17

hdoj 1977 Consecutive sum II的相关文章

HDU 1977 Consecutive sum II(数学)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1977 Problem Description Consecutive sum come again. Are you ready? Go ~~ 1    = 0 + 1 2+3+4    = 1 + 8 5+6+7+8+9  = 8 + 27 - You can see the consecutive sum can be representing like that. The nth line w

HDU1977 Consecutive sum II【水题】

Consecutive sum II Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2237    Accepted Submission(s): 1093 Problem Description Consecutive sum come again. Are you ready? Go ~~ 1    = 0 + 1 2+3+4  

【LeetCode】167. Two Sum II - Input array is sorted

Two Sum II - Input array is sorted Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they a

hdoj 1023 Train Problem II 【卡特兰】+【高精度】

题意:询问有多少种进站出站的顺序. 经典卡特兰.我对卡特兰目前的认识就是有n个1和n个-1,组成一个为2n的数列的方式有多少种.这就跟火车进站出站类似, 至于具体的卡特兰数的介绍,百度解释的很详细. 代码1(c语言): /* h(n) = h(n-1)*(4*n-2)/(n+1); */ #include <stdio.h> #include <string.h> #define M 110 int s[M][M] = {0}, b[M]; void init(){ s[1][0]

hdoj 1003 Max Sum 【最大子段和】【贪心】

题意:... 策略:看着像贪心,感觉也是贪心. 很久之前做的,又做了一遍,好题. 代码: #include<stdio.h> #include<string.h> int s[100005]; int main() { int t, i, j, l, st, en, n, v = 1; scanf("%d", &t); while(t --){ scanf("%d", &n); for(i = 1; i <= n; i

【Leetcode】Path Sum II

Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22, 5 / 4 8 / / 11 13 4 / \ / 7 2 5 1 return [ [5,4,11,2], [5,8,4,5] ] 思路:与[Leetcode]Path Sum 不同

leetcode_113题——Path Sum II(深度优先搜索)

Path Sum II Total Accepted: 41402 Total Submissions: 155034My Submissions Question Solution Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example:Given the below binary tree and sum = 22, 5

【leetcode】Combination Sum II

Combination Sum II Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each number in C may only be used once in the combination. Note: All numbers (including t

LeetCode: Combination Sum II 解题报告

Combination Sum II Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each number in C may only be used once in the combination. Note:All numbers (including ta