Detachment

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1868    Accepted Submission(s): 522

Problem Description
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,a2, … (x= a1+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≠aj when i≠j).
2.Make this multidimensional space size s as large as possible (s= a1∗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
思路:拆成连续的数字,剩余的从后往前加在每个数字上。

代码:

 #include<bits/stdc++.h>
//#include<regex>
#define db double
#include<vector>
#define ll long long
#define vec vector<ll>
#define Mt vector<vec>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define MP make_pair
#define PB push_back
#define inf 0x3f3f3f3f3f3f3f3f
#define fr(i,a,b) for(int i=a;i<=b;i++)
const int N=1e5+;
const int mod=1e9+;
const int MOD=mod-;
const db eps=1e-;
const db PI=acos(-1.0);
using namespace std;
ll x;
ll F[N],inv[N],Finv[N];
bool cal(ll n){
if((n*n+n-)/<=x) return ;
return ;
} void init(){
inv[] = ;
for(int i = ; i < ; i ++){
inv[i] = (mod - mod / i) * 1ll * inv[mod % i] % mod;//单个逆元
}
F[] = Finv[] = ;
for(int i = ; i < ; i ++){
F[i] = F[i-] * 1ll * i % mod;//阶乘
Finv[i] = Finv[i-] * 1ll* inv[i] % mod;//逆元阶乘
}
}
int main(){
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
int t;
ci(t);
init();
while(t--)
{
cl(x);
if(x<) {pl(x);continue;}
ll l=,r=,sum;
while(l<r){
ll mid=l+(r-l+)/;
if(cal(mid)) l=mid;
else r=mid-;
}
ll ans=x-(l*l+l-)/;
if(ans==l) sum=F[l+]*inv[]%mod*inv[l+]%mod;
else sum=F[l+]*Finv[l-ans+]%mod*F[l-ans]%mod;
pl(sum);
}
return ;
}

HDU 5976 数学的更多相关文章

  1. HDU 5976 数学,逆元

    1.HDU 5976 Detachment 2.题意:给一个正整数x,把x拆分成多个正整数的和,这些数不能有重复,要使这些数的积尽可能的大,输出积. 3.总结:首先我们要把数拆得尽可能小,这样积才会更 ...

  2. HDU 5984 数学期望

    对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...

  3. HDU 5976 Detachment(拆分)

    HDU 5976 Detachment(拆分) 00 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   Problem D ...

  4. HDU 5976 Detachment 打表找规律

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5976 Detachment Time Limit: 4000/2000 MS (Java/Other ...

  5. HDU 5976 Detachment 【贪心】 (2016ACM/ICPC亚洲区大连站)

    Detachment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  6. *HDU 2451 数学

    Simple Addition Expression Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  7. [ An Ac a Day ^_^ ] hdu 4565 数学推导+矩阵快速幂

    从今天开始就有各站网络赛了 今天是ccpc全国赛的网络赛 希望一切顺利 可以去一次吉大 希望还能去一次大连 题意: 很明确是让你求Sn=[a+sqrt(b)^n]%m 思路: 一开始以为是水题 暴力了 ...

  8. hdu 4506(数学,循环节+快速幂)

    小明系列故事——师兄帮帮忙 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Tot ...

  9. hdu 4432 数学杂题

    http://acm.hdu.edu.cn/showproblem.php?pid=4432 6分钟写的代码,一上午去调试,, 哎,一则题目没看懂就去写了,二则,哎,,恶心了.在坚持几天然后ACM退役 ...

随机推荐

  1. asp.net core策略授权

    在<asp.net core认证与授权>中讲解了固定和自定义角色授权系统权限,其实我们还可以通过其他方式来授权,比如可以通过角色组,用户名,生日等,但这些主要取决于ClaimTypes,其 ...

  2. docker 添加国内源

    docker for mac 获取地址:dao镜像地址  # 163的地址 https://hub-mirror.c.163.com docker for mac的设置操作:   点击Apply ...

  3. Spring框架Controller层(表现层)针对方法参数是Bean时HttpServletRequest绑定参数值问题解释

    在做项目的时候,有一个需求是将数据库中的信息封装到实体类返回到jsp界面 传过来的参数只是实体类的id属性,然后根据id属性去查数据库,事情就是这样,然后 结果遇到很奇怪的事情,在jsp页面中使用EL ...

  4. Grails笔记三:完整的文件上传实例

    文件上传在web应用中是比较普遍的,相对于使用jsp等技术实现文件上传,Grails的文件上传着实让人喜爱,因为极其简单,让人看一遍就容易轻松记住!不多说,实例如下: 假设已有一个名为uploadFi ...

  5. 在centos6上实现编译安装lamp和wordpress,并编译xcache

    author:JevonWei 版权声明:原创作品 软件环境: centos6.9 httpd-2.4.27.tar.bz2 apr-1.5.2.tar.bz2 apr-util-1.5.4.tar. ...

  6. Linq--一个集合中查找另一个集合,需熟悉这种写法

    //获取科室与病区授权的护士信息        public List<SYS_ZGKSBQDYK> GetUserWardMapByWardCode(string wardCode)   ...

  7. react 入门

    一:virtual DOM  虚拟DOM树 在React中,render执行的结果得到的并不是真正的DOM节点,结果仅仅是轻量级的JavaScript对象,我们称之为virtual DOM. 虚拟DO ...

  8. JS基础--函数与BOM、DOM操作、JS中的事件以及内置对象

       前   言 絮叨絮叨 这里是JS基础知识集中讲解的第三篇,也是最后一篇,三篇JS的基础,大多是知识的罗列,并没有涉及更难得东西,干货满满!看完这一篇后,相信许多正在像我一样正处于初级阶段的同学, ...

  9. 一些LVS实验配置、工具和方案

    最近做了一些LVS配置和方案的验证实验,将过程中用到的一些配置.工具和具体的解决方案记录一下.使用DR模式.验证一种不中断业务的RealServer升级或者重启方案. 网络规划: 节点 IP地址 ce ...

  10. GUI(JMenuBar+JMenu+JMenuItem)

    public class WindowMenu extends JFrame { JMenuBar menubar; JMenu menu,subMenu; JMenuItem item1,item2 ...