Formula

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1204    Accepted Submission(s): 415

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
 
题解:F[n] = 1n*2n-1*3n-2...*n ,这里的 F[n] 是可以通过一层循环就求解出来的,但是还是会超时。只能够将所有的询问保存下来,然后排个序,但是数字太大明显不能够作为下标,开个结构体记录下标,然后离散化下标,最后找到下标依次输出。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include <queue>
using namespace std;
typedef long long LL;
const LL mod = ;
struct Ask
{
LL v;
int ori;
} ask[];
LL a[];
int cmp(Ask a,Ask b){
return a.v<b.v;
}
int main()
{
int n,id=;
ask[].v = ask[].ori = ;
while(scanf("%d",&n)!=EOF)
{
ask[id].v = n;
ask[id].ori = id;
id++;
}
sort(ask+,ask+id,cmp);
for(int i=;i<id;i++){
a[ask[i].ori] = i;
}
LL cnt = ,ans=;
for(int i=; i<id; i++)
{
for(int j=ask[i-].v+; j<=ask[i].v; j++)
{
cnt = cnt*j%mod;
ans = ans*cnt%mod;
}
a[ask[i].ori] = ans;
}
for(int i=;i<id;i++){
printf("%lld\n",a[i]);
}
}

最新文章

  1. WinForm BaseClass类常用通用方法
  2. java Servlet(续)
  3. 回归 从注释开始 appledoc
  4. asp.net中ScriptManager自带Ajax与jQuery事件冲突
  5. Spring 创建bean的模式
  6. ubuntu开机自动关闭独显,使用集成显卡
  7. Session Cookie的HttpOnly和secure属性
  8. Redis集群伸缩
  9. 1-HTML Attributes
  10. [拍摄]日本AVENIR 6-36mm老式变焦镜头拆解 型号SSL06036M
  11. 如何利用Hadoop存储小文件
  12. 【Linux学习二】文件系统
  13. gradle构建工具入门
  14. 关于网站中Logo部分的写法
  15. 【Luogu P4074】[WC2013]糖果公园(树上带修改莫队)
  16. Oracle 12C -- 基于sequence的列的默认值
  17. 前段js初学总结
  18. ZooKeeper分布式专题与Dubbo微服务入门
  19. taskAffinity属性
  20. HTTP 请求头中的 X-Forwarded-For(转)

热门文章

  1. MySQL之查询性能优化(二)
  2. 《Cracking the Coding Interview》——第7章:数学和概率论——题目4
  3. asp.net 身份验证-Form 身份验证
  4. python_ 运算符与分支结构
  5. NYOJ 简单数据结构
  6. node + express + iis + iisnode + urlrewrite搭建站点
  7. PAT 甲级 1011 World Cup Betting
  8. VB.NET视频总结——基础篇
  9. web自动化测试:watir+minitest(四)
  10. springmvc中RedirectAttributes、SessionFlashMapManager的作用