hdu 5976
来源:互联网 发布:数据科学实战手册 编辑:程序博客网 时间:2024/06/09 17:32
#include <iostream>#include <cstdio>#include <cmath>#include <string.h>#include <queue>#include <stack>#include <algorithm>#include <fstream>#define ll long long#define INF 0x3f3f3f3f#define clr(x) memset(x,0,sizeof(x))#define clr2(x) memset(x,INF,sizeof(x))#define clr3(x) memset(x,-INF,sizeof(x))#define clr4(x) memset(x,-1,sizeof(x))#define pb(x) push_back(x)//#define debugusing namespace std;const ll mod=1e9+7;ll fact[2333333];//计算a^b mod nll modexp(ll a,ll b,ll n){ ll ret=1; ll tmp=a; while(b) { //基数存在 if(b&0x1) ret=ret*tmp%n; tmp=tmp*tmp%n;// 计算a^(2*i) 但b的二进制位是0的时候相当于ret*1所以不用考虑 b>>=1; } return ret;}ll inv(ll k){ return modexp(k,mod-2,mod);}void init(){ fact[1]=1; for (int i=2; i*i<2e9+2333; i++) fact[i]=fact[i-1]*i % mod;}void solve(){ ll x; scanf("%lld",&x); if (x<=4) { printf("%d\n",x); return ; } int st=2; int t= floor ( (-1 + sqrt(1+8*(1+x))) /2 ); int ed=t; int k=x- ( t*(t+1)/2 - 1); st+= k / (t-1); ed+= k / (t-1); int m=k% (t-1); ll res=0; if (m==0) res= fact[ed] * inv(fact[st-1]) % mod; else { int bk=ed-m+1; res=fact[bk-1]*inv(fact[st-1])%mod; bk++; ed++; res*= fact[ed]*inv(fact[bk-1])%mod; res%=mod; } printf("%lld\n",res);}int main(){#ifdef debug freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);#endif init(); int T; scanf("%d",&T); while (T--) solve(); return 0;}
0 0
- hdu 5976
- HDU 5976
- HDU 5976 逆元
- HDU 5976 Detachment
- HDU 5976 Detachment
- HDU 5976 Detachment
- hdu 5976 Detachment
- HDU 5976 Detachment
- HDU 5976 Detachment
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- POJ 3181 Dollar Dayz (有点像背包的dp -- JAVA大数)
- Tomcat外网部署、配置
- Unity3D获取GameObject的所有子对象,添加特定标签
- IO流学习笔记
- 窗口移动到屏幕边缘时自动排列窗口
- hdu 5976
- 数字排序转变为字母排序
- Mac抓取移动端HTTP数据包 抓包工具 Charles 的使用
- 练习实录
- 镜像文件
- 快速排序
- 黑盒测试
- Java虚拟机工作原理详解
- buildroot编译交叉编译器