HDU1977:Consecutive sum II
来源:互联网 发布:网络电话短信软件 编辑:程序博客网 时间:2024/05/21 19:23
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.
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).
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.
All answer in the range of signed 64-bits integer.
Sample Input
3012
Sample Output
0 11 88 27
这道题我只能说数据太水了
先说说题意吧
0 : 1 = 0 ^3+ 1^3
1: 2 + 3 + 4 = 1^3 + 2^3
2: 5 + 6 + 7 + 8 + 9 = 2^3 + 3^3
3: 10 + 11 + 12 + 13 + 14 + 15 = 3^3 + 4^3
所以得 n = n^3 + (n+1)^3
问题是n最大的2100000,理论就算是__int64也装不下
但是用__int64也过了,真是数据太水了= =
先贴大数的:
#include <stdio.h>#include <string.h>#include <stdlib.h>void mult(char a[],char b[],char s[]){ int i,j,k = 0,alen,blen,sum = 0,res[65][65]= {0},flag = 0; char result[65]; alen = strlen(a); blen = strlen(b); for(i = 0; i<alen; i++) { for(j = 0; j<blen; j++) res[i][j] = (a[i]-'0')*(b[j]-'0'); } for(i = alen-1; i>=0; i--) { for(j = blen-1; j>=0; j--) { sum = sum+res[i+blen-j-1][j]; } result[k] = sum%10; k++; sum = sum/10; } for(i = blen-2; i>=0; i--) { for(j = 0; j<=i; j++) { sum = sum+res[i-j][j]; } result[k] = sum%10; k++; sum = sum/10; } if(sum) { result[k] = sum; k++; } for(i = 0; i<k; i++) result[i]+='0'; for(i = k-1; i>=0; i--) s[i] = result[k-1-i]; s[k] = '\0'; while(1) { if(strlen(s)!=strlen(a) && s[0] == '0') strcpy(s,s+1); else break; }}void add(char a[],char b[],char back[]){ int i,j,k,up,x,y,z,l; char *c; if(strlen(a) > strlen(b)) l = strlen(a)+2; else l = strlen(b)+2; c = (char*)malloc(l*sizeof(char)); i = strlen(a)-1; j = strlen(b)-1; k = 0; up = 0; while(j>=0 || i>=0) { if(i<0) x = '0'; else x = a[i]; if(j<0) y = '0'; else y = b[j]; z = x-'0'+y-'0'; if(up) z++; if(z>9) { up = 1; z%=10; } else up = 0; c[k++] = z+'0'; i--; j--; } if(up) c[k++] = '1'; i = 0; c[k] = '\0'; for(k-=1; k>=0; k--) back[i++] = c[k]; back[i] = '\0';}int main(){ int k; char a[100],b[100],t[100]; scanf("%d%*c",&k); while(k--) { scanf("%s",a); add(a,"1",b); strcpy(t,a); mult(t,t,a); mult(a,t,a); strcpy(t,b); mult(t,t,b); mult(b,t,b); printf("%s %s\n",a,b); memset(a,'\0',sizeof(a)); memset(b,'\0',sizeof(b)); } return 0;}
然后是水:
#include <stdio.h>int main(){ int k; scanf("%d",&k); while(k--) { __int64 n,m; scanf("%I64d",&n); m = n+1; n = n*n*n; m = m*m*m; printf("%I64d %I64d\n",n,m); } return 0;}
- HDU1977:Consecutive sum II
- HDU1977 Consecutive sum II【水题】
- HDU1977 Consecutive sum II【数学计算+水题】
- Consecutive sum II 1977
- Consecutive sum II 1977
- HDOJ1977 Consecutive sum II
- nyoj-879-Consecutive sum II
- hdu 1977 Consecutive sum II
- hdoj 1977 Consecutive sum II
- hdu-1977 Consecutive sum II
- hdoj-1977-Consecutive sum II
- HDOJ 1977 Consecutive sum II
- HDU 1977 Consecutive sum II(数学)
- HDOJ(HDU) 1977 Consecutive sum II(推导、、)
- HDU 1977 Consecutive sum II【英语题+数学题】
- HDU 1977 Consecutive sum II
- HDU1868:Consecutive sum
- Sum of Consecutive Primes
- [Python]copy模块学习 -- 深拷贝和浅拷贝
- 腾讯推出HTML5开源专业在线图像处理引擎
- jquery设置和获取html,文本,值
- mysql查看数据库日志
- 1015 两数交换输出顺序
- HDU1977:Consecutive sum II
- 重载和重写的区别
- 【模式匹配】之 —— BM算法
- Java基础—再续多线程
- 如何检测 Android Cursor 泄漏
- Linux下删除指定文件之外的其他文件
- 第四周项目5
- Web后台开发基本分析方法
- spring 注入bean 时的初始化