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 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

Author

Wiskey

Source

2008杭电集训队选拔赛

PS:

找到规律就OK啦2333333333!

代码如下:

#include <cstdio>
int main()
{
    int t;
    __int64 n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%I64d",&n);
        printf("%I64d %I64d\n",n*n*n,(n+1)*(n+1)*(n+1));
    }
    return 0;
}

时间: 2024-10-28 10:14:58

HDU 1977 Consecutive sum II(数学)的相关文章

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 + 12+3+4    =

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  

hdu 1868 Consecutive sum

我们假设成立数列的首相和末项分别为a和b, 由求和公式可得(a+b)*(b-a-1)/2==n;再设a+b=x,b-a+1=y,则有方程组 x*y=n*2, 两式相加得x+y=2*b+1,故有x+(2*n/x)=2*a-1 因此我们只要检测能被2*n整除且使上面方程满足中a为正整数的情况(b比a大,b就不用判断了),由于3*5与5*3是同一种情况,所以只需要从1循环到sqrt(n) ,889ms险过 #include<iostream> #include<cmath> using

[2016-03-28][HDU][1024][Max Sum Plus Plus]

时间:2016-03-28 17:45:33 星期一 题目编号:[2016-03-28][HDU][1024][Max Sum Plus Plus] 题目大意:从n个数字提取出一定数字组成m个部分,使得这个部分的总和最大 分析: dp[i][j]表示前i段计算第j个数字,dp[i][j] = max(dp[i - 1][j - 1] + a[j],dp[i][k] + a[j]); #include <algorithm> #include <cstring> #include &

hdu 3081 hdu 3277 hdu 3416 Marriage Match II III IV //最大流的灵活运用

3081 题意: n个女孩选择没有与自己吵过架的男孩有连边(自己的朋友也算,并查集处理),2分图,有些边,求有几种完美匹配(每次匹配每个点都不重复匹配) 我是建二分图后,每次增广一单位,(一次完美匹配),再修改起点还有终点的边流量,继续增广,直到达不到完美匹配为止.网上很多是用二分做的,我觉得没必要...(网上传播跟风真严重...很多人都不是真正懂最大流算法的...) 3277 : 再附加一条件,每个女孩可以最多与k个自己不喜欢的男孩.求有几种完美匹配(同上). 我觉得:求出上题答案,直接ans

hdu 2576 Another Sum Problem

题目大意:求前n项和的前n项和. 数学推导题,f(n)=n*(n+1)*(n+2)/6 推导思路如下: #include"cstdio" #include"cstring" #include"cmath" #include"cstdlib" #include"iostream" #include"algorithm" #include"queue" using nam

HDU 4569 Special equations(数学推论)

题目 //想不出来,看了解题报告 /* 题意:给你一个最高幂为4的一元多项式,让你求出一个x使其结果模p*p为0. 题解:f(x)%(p*p)=0那么一定有f(x)%p=0,f(x)%p=0那么一定有f(x+p)%p=0. 所以我们可以开始从0到p枚举x,当f(x)%p=0,然后再从x到p*p枚举,不过每次都是+p,找到了输出即可,没有的话No solution! */ #include<stdio.h> int main() { int t,n; __int64 a[5],p; scanf(

HDU 1018 Big Number (简单数学)

Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25649    Accepted Submission(s): 11635 Problem Description In many applications very large integers numbers are required. Some of these

hdu 3081 Marriage Match II (二分+最大流+并查集)

hdu 3081 Marriage Match II Description Presumably, you all have known the question of stable marriage match. A girl will choose a boy; it is similar as the game of playing house we used to play when we are kids. What a happy time as so many friends p