HDU 5139 Formula(递推公式、离线处理)
2015-08-27 09:51
423 查看
Formula
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1094 Accepted Submission(s): 384
Problem Description
f(n)=(∏i=1nin−i+1)%1000000007
You are expected to write a program to calculate f(n) when a certain n is given.
Input
Multi test cases (about 100000), every case contains an integer n in a single line.
Please process to the end of file.
[Technical Specification]
1≤n≤10000000
Output
For each n,output f(n) in a single line.
Sample Input
2 100
Sample Output
2 148277692
Source
BestCoder Round #21
题目大意:给出n,求函数
的值。
解题思路:递推公式:
,由于数据比较大,打表会超内存,可以对数据进行离线处理。
代码如下:
#include <cstdio> #include <iostream> #include <cstdlib> #include <cstring> #include <cmath> #include <string> #include <algorithm> #include <vector> #include <deque> #include <list> #include <set> #include <map> #include <stack> #include <queue> #include <numeric> #include <iomanip> #include <bitset> #include <sstream> #include <fstream> #include <limits.h> #include <ctime> #define debug "output for debug\n" #define pi (acos(-1.0)) #define eps (1e-6) #define inf (1<<28) #define sqr(x) (x) * (x) #define mod 1000000007 using namespace std; typedef long long ll; struct node { ll n; ll i; ll f; }a[100005]; bool cmp(node a,node b) { return a.n<b.n; } bool cmp1(node a,node b) { return a.i<b.i; } int main() { ll i,j,k,n; while(~scanf("%I64d",&n)) { a[k].i=k; a[k++].n=n; } sort(a,a+k,cmp); ll fac=1,f=1; for(i=0,j=2;i<k;i++) { for(;j<=a[i].n;j++) { fac=fac*j%mod; f=f*fac%mod; } a[i].f=f; } sort(a,a+k,cmp1); for(i=0;i<k;i++) printf("%I64d\n",a[i].f); return 0; }
相关文章推荐
- 安装kafka到window上,编写kafka java客户端连接kafka
- HBase基础知识(7):扫描操作之ResultScanner类
- mysql修改表、字段、库的字符集
- [笔试]设计模式小结
- iOS开发-关闭/收起键盘方法总结
- JAVA流技术(IO编程)
- IOS开发之----Mac终端 常用命令
- 菜鸟vimer成长记——第4.1章、通用插件
- js 参数的 引用与值传递
- 2015.6.23(Metaq和HSF)
- 输出单向链表中倒数第k个结点
- 虚拟机安装REDHAT没有网卡ETH0的问题处理
- 张国祥老师应邀参加成都西部企业家论坛活动
- hdoj.2067 小兔的棋盘【卡特兰数列】 2015/08/27
- 社説 20150827 企業年金改革 多くの人が活用できる制度に
- 面向对象的三个基本特征是:封装、继承、多态
- Could not create the view: An unexpected exception was thrown tomcat中 Servlet 错误解决方法
- Leetcode: Reverse Integer
- 人工智能与模式识别 --中国计算机学会推荐国际学术刊物
- 面试总结——&a+1