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

看到有很多人的这个题目是找规律做的,我开始没注意规律了,

就打表做了。。。。

现在给出2种能AC的方法:

第一种:打表:

import java.util.Scanner;

public class Main{
static long[] db1 = new long[2100005];
public static void main(String[] args) {
dabiao();
//System.out.println("aa");
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
System.out.println(db1[n]+" "+db1[n+1]);
}
}
private static void dabiao() {
db1[0] = 0;
db1[1] = 1;
db1[2] = 8;
db1[3] = 27;
long k=9;
long num =7;
Scanner sc = new Scanner(System.in);
for(int i=4;i<=2100001;i++){
db1[i] =(k+num/2+1)*num-db1[i-1];
// System.out.println(k);
// System.out.println(num/2+1);
//
// System.out.println(i);
// System.out.println(db1[i]);
// System.out.println((k+num/2+1)*num);
// int m = sc.nextInt();
k=k+num;
num+=2; }
}
}

第二种:找规律:

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t =sc.nextInt(); while(t-->0){
long n =sc.nextLong();
System.out.println(n*n*n+" "+(n+1)*(n+1)*(n+1));
}
}
}

HDOJ(HDU) 1977 Consecutive sum II(推导、、)的更多相关文章

  1. hdoj 1977 Consecutive sum II

    Consecutive sum II Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  2. HDOJ(HDU).1003 Max Sum (DP)

    HDOJ(HDU).1003 Max Sum (DP) 点我挑战题目 算法学习-–动态规划初探 题意分析 给出一段数字序列,求出最大连续子段和.典型的动态规划问题. 用数组a表示存储的数字序列,sum ...

  3. HDOJ/HDU 1297 Children’s Queue(推导~大数)

    Problem Description There are many students in PHT School. One day, the headmaster whose name is Pig ...

  4. HDOJ(HDU) 2524 矩形A + B(推导公式、)

    Problem Description 给你一个高为n ,宽为m列的网格,计算出这个网格中有多少个矩形,下图为高为2,宽为4的网格. Input 第一行输入一个t, 表示有t组数据,然后每行输入n,m ...

  5. HDOJ(HDU).1258 Sum It Up (DFS)

    HDOJ(HDU).1258 Sum It Up (DFS) [从零开始DFS(6)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双 ...

  6. HDU 1024 Max Sum Plus Plus (动态规划)

    HDU 1024 Max Sum Plus Plus (动态规划) Description Now I think you have got an AC in Ignatius.L's "M ...

  7. HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)

    HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...

  8. HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)

    HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...

  9. HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)

    HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...

随机推荐

  1. POJ2250:Compromise(LCS)

    Description In a few months the European Currency Union will become a reality. However, to join the ...

  2. Array数组基本案例:图书基本录入输出系统

    import java.util.Scanner; public class ArrayTest{ public static void main(String args[]){ Scanner sc ...

  3. Delpoyment assembly

    遇见异常: java.lang.ClassNotFoundException: 原因:没有对tomcat进行依赖说明 解决: properties - Delpoyment assembly 将tom ...

  4. 《Android开发艺术探索》读书笔记 (3) 第3章 View的事件体系

    本节和<Android群英传>中的第五章Scroll分析有关系,建议先阅读该章的总结 第3章 View的事件体系 3.1 View基本知识 (1)view的层次结构:ViewGroup也是 ...

  5. Android(java)学习笔记224:横竖屏切换时Activity的生命周期

    1.横竖屏切换的生命周期     默认情况下横竖屏切换,先销毁再创建 2.有的时候,默认情况下的横竖屏切换(先销毁再创建),对应用户体验是不好的,比如是手机游戏横竖屏切换对游戏体验非常不好,下面两种方 ...

  6. 鼠标双击范围基于Win7

    TP鼠标双击范围主要是修改Registry中的HKEY_CURRENT_USER\Control Panel\Mouse里面的两个参数 DoubleClickHeight跟DoubleClickWid ...

  7. zabbix图中出现中文乱码问题

    我这周部署了zabbix监控服务器,但是配置过程中发现当有中文时,图中的中文会变成方块 如下图所示: 这个问题是由于zabbix的web端没有中文字库,我们最需要把中文字库加上即可 解决办法如下 1. ...

  8. 5事件DOM零级事件跟DOM二级事件

    事件的行为传播,行为本身跟事件绑定没有关系:1.全新认识事件(某一个具体的行为)->行为本身:浏览器天生自带的一些行为操作->click,mouseover(mouseenter),mou ...

  9. Effective java-泛型思维导图

  10. Activity之间的数据传递(Arraylist)

    1.使用Serialiable方法 实现序列化 2.使用Parcelable方法(这是android自己封装的类) Parcel类是封装数据的容器,封装后的数据通过Intent和IPC传递     实 ...