2016ICPC大连站 F Detachment【数学】
来源:互联网 发布:web前端美工 编辑:程序博客网 时间:2024/06/10 17:33
In a highly developed alien society, the habitats are almost infinite dimensional space.
In the history of this planet,there is an old puzzle.
You have a line segment with x units’ length representing one dimension.The line segment can be split into a number of small line segments: a1,a2a1,a2, … (x= a1+a2a1+a2+…) assigned to different dimensions. And then, the multidimensional space has been established. Now there are two requirements for this space:
1.Two different small line segments cannot be equal ( ai≠ajai≠aj when i≠j).
2.Make this multidimensional space size s as large as possible (s= a1∗a2a1∗a2*…).Note that it allows to keep one dimension.That’s to say, the number of ai can be only one.
Now can you solve this question and find the maximum size of the space?(For the final number is too large,your answer will be modulo 10^9+7)
Input
The first line is an integer T,meaning the number of test cases.
Then T lines follow. Each line contains one integer x.
1≤T≤10^6, 1≤x≤10^9
Output
Maximum s you can get modulo 10^9+7. Note that we wants to be greatest product before modulo 10^9+7.
Sample Input
1
4
Sample Output
4
从2开始选取最接近的数,无法叠加时,将多余的部分平均分配给靠后的数字(+1)。
如果恰好剩余的数等于最后一个数,最后一个数+2。
#include <iostream>#include <stdio.h>#include <math.h>#include <string.h>#include <vector>#include <algorithm>using namespace std;#define LL long longconst LL maxn = 45000+44;const LL mod = 1e9+7;LL x[maxn];LL j[maxn];LL qkm(LL base,LL mi){ LL ans=1; base%=mod; while(mi){ if(mi&1) ans=ans*base; base=base*base; mi>>=1; base%=mod; ans%=mod; } return ans;}int main(){ x[1]=0; LL cnt; for(cnt=2;;cnt++){ x[cnt]=x[cnt-1]+cnt; if(x[cnt]>=1e9) break; } j[1]=1; for(LL i=2;i<=cnt;i++){ j[i]=j[i-1]*i%mod; } LL T;scanf("%lld",&T); while(T--){ LL n;scanf("%lld",&n); LL now=0; LL k=0; k=upper_bound(x+1,x+1+cnt,n)-x; if(x[k]>n) k--; now=x[k]; // printf("%lld %lld\n",now,k); LL shen=n-now; LL ans; if(n<=4) { printf("%lld\n",n); continue; } if(shen==k){ ans=j[k+2]*qkm(2,mod-2)%mod*qkm(k+1,mod-2)%mod;//!!!!NIYUAN; } else { ans=j[k+1]*qkm(k+1-shen,mod-2)%mod; } printf("%lld\n",ans); } return 0;}
- 2016ICPC大连站 F Detachment【数学】
- HDU 5976 && 2016ICPC大连 F: Detachment(找规律)
- HDU 5976 Detachment 【贪心】 (2016ACM/ICPC亚洲区大连站)
- Detachment (Hdu5976)2016大连现场赛F题
- HDOJ 5976 Detachment【2016大连现场】【数学好题】
- 2016ACM/ICPC亚洲区大连站 1006 Detachment 1004 A Simple Math Problem(求逆元)(数论)
- 2016ICPC大连站 A
- 2016ICPC大连站 H
- 2016 ICPC 大连站解题报告
- 2016ICPC大连站 I Convex【几何】
- HDU 5974 A Simple Math Problem(数学解方程)——2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)
- acm-icpc大连站随笔
- 2016 ICPC 大连 网络赛
- 2016-ICPC-大连赛区总结
- HDU5971, 2016ACM/ICPC亚洲区大连站第一题
- 2016 acm/icpc 大连站现场赛(7道题)
- 2016年ACM/ICPC大连站(第一块铁牌)
- 2016ICPC大连站 J Find Small A【water】
- Android-集成微信支付以及遇到的问题浅谈
- 理解S12(X)架构中的地址映射方案
- JQuery国际化语言
- OpenCV-统计图像的直方图,绘制直方图
- 51Nod-1208-Stars in Your Window
- 2016ICPC大连站 F Detachment【数学】
- 2017.9.28 CF #R2 B 思考记录
- hdu 6212 Zuma 题解
- 更换了电脑如何更新博客
- 深入学习python之scikit-learn的线性模拟
- jsp页面访问servlet
- windows下mysql主从部署
- c数组与指针难点
- C++基础-虚函数/纯虚函数/普通函数