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. [2017-08-07]ABP系列——QuickStartA:概述、思想、入门和HelloWorld

    唔,说好的文章,欠了好久,先水一篇. 本系列目录:Abp介绍和经验分享-目录 概述 先表个态:对绝大多数人来说,ABP是成熟的,足以用到生产环境的. 最适合的:业务非常复杂且不追求极致性能的(这里并不 ...

  2. python条件判断与循环

    条件判断 1.python缩进规则: 如果if语句判断是True,就把缩进的语句执行了,否则,什么也不做,比如: age=20 if age >= 18: print('your age is' ...

  3. flume 搭建

    Flume使用 1安装及修改初始环境 安装见:http://blog.csdn.net/qianshangding0708/article/details/48088611 配置在conf目录下配置如 ...

  4. UWP 手绘视频创作工具技术分享系列

    开篇先来说一下写这篇文章的初衷. 初到来画,通读了来画 UWP App 的代码,发现里面确实有很多比较高深的技术点,同时也是有很多问题的,扩展性,耦合,性能,功能等等.于是我们决定从头重构这个产品,做 ...

  5. Javascript的内容摘要

    JS简介和变量 {JS的三种方式}            1 HTML中内嵌JS(不提倡使用)            <button onclick="javascript:alert ...

  6. jQuery EasyUI弹出确认对话框(确认操作中.....)

    因为毕业设计的原因,在初期设计系统的时候没有考虑功能的正确性,所以很多的功能都没有加验证和确认的操作,给人在操作方面上有一些不好的感觉(可能失误点击后,数据就别删除,或者增加了),所以在网上找了一些资 ...

  7. spring整合mybatis错误:HTTP Status 404 - xxx-xxx....

    运行环境:jdk1.7.0_17 + tomcat 7 + spring 3.2.0 +mybatis 3.2.7+ eclipse,访问路径:http://localhost:8085/Spring ...

  8. HTTP协议是无状态协议,怎么理解

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp24 HTTP协议是无状态协议,怎么理解?  2010-02-23 09:4 ...

  9. 2016-2017-2 《Java 程序设计》课堂实践项目

    目录 基本工具 基础内容 Hello World 和 模块分解 数组的使用 命令行参数 递归 分支语句 String类的使用 类的定义与测试 多态 IO与异常 数据库 网络与安全 数据结构应用 And ...

  10. GUI(自定义背景图片)

    如果组件中没有setIcon(...);这个方法,这是有需要给组件设置背景图片,这时就可以自定义绘制背景图片 /** * */ package com.niit.javagui; import jav ...