Faulhaber’s Triangle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 157    Accepted Submission(s): 78

Problem Description
The sum of the m
th powers of the first n integers

S(n,m) = SUM ( j= 1 to n)( j
m)

Can be written as a polynomial of degree m+1 in n:

S(n,m) = SUM (k = 1 to m+1)(F(m,k) *n
k)

Fo example:

The coefficients F(m,k) of these formulas form Faulhaber‘s Tr angle:


where rows m start with 0 (at the top) and columns k go from 1 to m+1

Each row of Faulhaber‘s Tr angle can be computed from the previous row by:

a) The element in row i and column j ( j>1) is (i/j )*(the element above left); that is:

F(i,j ) = (i/j )*F(i-1, j-1)

b) The first element in each row F(i,1) is chosen so the sum of the elements in the row is 1

Write a program to find entries in Faulhaber‘s Tr angle as decimal f actions in lowest terms 

 
Input
The first line of input contains a single integer P, (1 <= P <= 1000), which is the number of data sets that follow. Each data set should be processed identically and independently

Each data set consists of a single line of input consisting of three space separated decimal integers The first integer is the data set number. The second integer is row number m, and the third integer is the index k within the row of the entry for which you are to find F(m, k), the Faulhaber‘s Triangle entry (0 <= m <= 400, 1 <= k <= n+1).

 
Output
For each data set there is a single line of output. It contains the data set number, followed by a single space which is then followed by either the value if it is an integer OR by the numerator of the entry, a forward slash and the denominator of the entry. 

 
Sample Input
4
1 4 1
2 4 3
3 86 79
4 400 401
 
Sample Output
1 -1/30
2 1/3
3 -22388337
4 1/401
 
Source
 
第一项等于1减去后面的所有项,注意一下,用__int64存,不然会爆掉,我的156ms还不错呢
今天做了几题,好充实的感觉,哈哈

#include<stdio.h>

struct nod{
__int64 a,b;
}s[405][405]; __int64 gy(__int64 a,__int64 b)
{
__int64 temp;
if(b==0||a==0)
return 0;
if(a<0)
a=-a;
if(b<0)
b=-b;
if(a<b)
{
temp=a;
a=b;
b=temp;
}
while((temp=a%b))
{
a=b;
b=temp;
}
return b;
}
int Init()
{
int i,j,k,n;
__int64 t1,t2,temp;
s[0][1].a=1;
s[0][1].b=1;
s[1][1].a=1;
s[1][1].b=2;
s[1][2].a=1;
s[1][2].b=2;
for(i=2;i<401;i++)
{
for(j=2;j<=i+1;j++)
{
t1=i*s[i-1][j-1].a;
t2=j*s[i-1][j-1].b;
if((temp=gy(t2,t1)))
{
t1/=temp;
t2/=temp;
}
else
{
t1=0;
t2=1;
}
s[i][j].a=t1;
s[i][j].b=t2;
}
t1=0;
t2=1;
for(j=2;j<=i+1;j++)//2项开始求后面的和
{
t1=t2*s[i][j].a+t1*s[i][j].b;
t2=t2*s[i][j].b;
if((temp=gy(t1,t2)))
{
t1/=temp;
t2/=temp;
}
else
{
t1=0;
t2=1;
}
}
t1=t2-t1;
if((temp=gy(t1,t2)))
{
t1/=temp;
t2/=temp;
}
else
{
t1=0;
t2=1;
}
s[i][1].a=t1;
s[i][1].b=t2;
}
return 1;
}
int main()
{
int i,j,k,n,t,no,x,y;
Init();
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&no,&x,&y);
printf("%d ",no);
if(s[x][y].a==0)
printf("0\n");
else if(s[x][y].b==1)
printf("%I64d\n",s[x][y].a);
else printf("%I64d/%I64d\n",s[x][y].a,s[x][y].b);
}
return 0;
}

hdu4488 Faulhaber’s Triangle(模拟题)的更多相关文章

  1. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  2. poj 1888 Crossword Answers 模拟题

    Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 D ...

  3. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  4. sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)

    The Android University ACM Team Selection Contest Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里 ...

  5. 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中

    题目名称 正确答案  序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...

  6. UVALive 4222 Dance 模拟题

    Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...

  7. cdoj 25 点球大战(penalty) 模拟题

    点球大战(penalty) Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...

  8. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  9. URAL 2046 A - The First Day at School 模拟题

    A - The First Day at SchoolTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

随机推荐

  1. iphone 与 ipad -- UIPopoverPresentationViewController

    iOS8.0之后, 苹果推出了UIPopoverPresentationViewController, 在弹出控制器时, 统一采用 presentViewController, 但是要实现iPhone ...

  2. CoreGraphics --- CGContext

    CGContext又叫图形上下文,相当于一块画布,以堆栈形式存放,只有在当前context上绘图才有效.iOS有分多种图形上下文,其中UIView自带提供的在drawRect:方法中通过UIGraph ...

  3. webservice 的权限验证

    1. http://blog.csdn.net/jaune161/article/details/25602655 2. http://wcp88888888.iteye.com/blog/13993 ...

  4. UOJ179 线性规划

    Description 这是一道模板题. 本题中你需要求解一个标准型线性规划: 有\(n\)个实数变量\(x_1,x_2,\cdots,x_n\)和\(m\)条约束,其中第\(i\)条约束形如\(\s ...

  5. 【网络流24题】 No.12 软件补丁问题(最小转移代价 最短路)

    [题意] T 公司发现其研制的一个软件中有 n 个错误, 随即为该软件发放了一批共 m 个补丁程序. 每一个补丁程序都有其特定的适用环境, 某个补丁只有在软件中包含某些错误而同时又不包含另一些错误时才 ...

  6. 编译GNU/Linux共享库, 为什么要用PIC编译?

    http://blog.csdn.net/chenji001/article/details/5691690

  7. Windows.document对象

    一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:var a =docunment.getElementById("i ...

  8. 【HDOJ】1512 Monkey King

    左偏树+并查集.左偏树就是可合并二叉堆. /* 1512 */ #include <iostream> #include <string> #include <map&g ...

  9. A WCF-WPF Chat Application

    http://www.codeproject.com/Articles/25261/A-WCF-WPF-Chat-Application

  10. tar 解压命令

    1.tar.gz文件的解压 tar zxvf  *.tar.gz 2.bz2属性的解压 tar jxvf  *.bz2