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. Junit单元测试实例

    1.非注解 public class Test { @org.junit.Test public void testPrice() { ClassPathXmlApplicationContext b ...

  2. 别只用hive写sql -- hive的更多技能

    hive是Apache的一个顶级项目,由facebook团队开发,基于java开发出面向分析师或BI等人员的数据工具(常用作出具仓库),它将文件系统映射为表,使用SQL实现mapreduce任务完成分 ...

  3. mysql添加外键约束变为索引

    今天有位自己填上一坑:mysql储存引擎 原因就是数据库表引擎为:MyISAM,建立主外键关系需要是InnoDB: 解决方案:alter  table table_name1  engine=inno ...

  4. vue-webpack-boilerplate分析

    看完这篇文章你会学到通过vue-cli创建的项目,执行npm run dev后都发生了什么事情以及执行流程. 在创建vue项目时,官方推荐使用vue-cli这个命令行工具. # 全局安装 vue-cl ...

  5. 手机设备访问PC页面如果跳转到手机页面?

    //例如:iphone访问www.baidu.com自动跳转到wap.baidu.com,只需在pc端模版页面引入以下js代码//pc zhuan mobile var mobileAgent = n ...

  6. 软工+C(2017第6期) 最近发展区/脚手架

    // 上一篇:工具和结构化 // 下一篇:野生程序员 教育心理学里面有提到"最近发展区"这个概念,这个概念是前苏联发展心理学家维果茨基(Vygotsky)提出的,英文名词是Zone ...

  7. 第四次作业 四则运算器在C++层面上的进一步思考

    OOA(Object Oriented Analysis,面向对象分析) 从客观存在的事务和事务之间的关系,归纳出有关对象(包括对象的属性和行为)以及对象之间的联系,并将具有相同属性和行为的对象用一个 ...

  8. 201521123075 《Java程序设计》第7周学习总结

    1. 本周学习总结 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代码 源代码为 public boolean contains(Object o) ...

  9. 201521123053 《Java程序设计》第5周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 1.2 可选:使用常规方法总结其他上课内容. 答:我开始做笔记了,在本周学习中的一些笔记 * abstract关键字是为了实现 ...

  10. 201521123039《java程序设计》第十四周学习总结

    1. 本周学习总结 2. 书面作业 1. MySQL数据库基本操作 建立数据库,将自己的姓名.学号作为一条记录插入.(截图,需出现自己的学号.姓名) 在自己建立的数据库上执行常见SQL语句(截图) 2 ...