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. QQ宠物吹泡泡游戏小助手 VC++6.0代码分析

    最近玩QQ宠物,他总是心情低落,让我很不爽,让他玩耍吧,还得自己点鼠标,所以想偷个懒,试试能不能编个程序让电脑帮我做这个事情. 要干这件事就得先找一个游戏开刀,刚开始我找的是弹力球游戏,不就是点鼠标么 ...

  2. JNI/NDK开发指南(一)—— JNI开发流程及HelloWorld

    转载请注明出处:http://blog.csdn.net/xyang81/article/details/41777471 JNI全称是Java Native Interface(Java本地接口)单 ...

  3. django入门教程(上)

    相信用过python的人都听过Django的大名,知道它是一个web框架,用来支持动态网站.网络应用程序以及网络服务的开发.那么为什么我们需要一个web框架,而不是直接用python来写web应用呢? ...

  4. bzoj 3153: Sone1 Toptree

    3153: Sone1 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 511  Solved: 202[Submit][Status][Discuss ...

  5. DHTMLX 前端框架 建立你的一个应用程序教程(二)--设置布局

    Layout控件的演示 Dhtmlx有很多的组建来组织网页的建设, 这篇主要介绍dhtmlxLayout . 下面图片中 布局将各个组件(1.Menu 2.Toolbar 3.Grid 4.Form ...

  6. binder

    Service与Android系统设计(7)--- Binder驱动 http://blog.csdn.net/21cnbao/article/details/8087354 Android Bind ...

  7. SPRING IN ACTION 第4版笔记-第二章-004-Bean是否单例

    spring的bean默认是单例,加载容器是会被化,spring会拦截其他再次请求bean的操作,返回spring已经创建好的bean. It appears that the CompactDisc ...

  8. 带圆角的EditText

    转载请注明出处:http://blog.csdn.net/krislight/article 1.定义一个Drawable <?xml version="1.0" encod ...

  9. hadoop2.2编程: 重写comparactor

    要点: 类型比较在hadoop的mapreduce中非常重要,主要用来比较keys; hadoop中的RawComparator<T>接口继承自java的comparator, 主要用来比 ...

  10. MySQL源码 数据结构array

    MySQL源码中自己定义了许多数据结构,放在mysys的目录下,源码中通常都使用这些数据结构来组织存放数据,也更容易实现跨平台.   下面先来看下MySQL定义的动态数组: [源代码include/a ...