Detachment

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

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
 
Source
 
题意:有一个数字n,将它拆分成m个数,这m个数相加等于n,且这m个数各不相同  问怎样拆分使得这m个数的乘积最大,输出这个最大的乘积值
将n拆成 2 3 4 5 6 7 8 9 .........l +r 这样的形式,这样可以保证m的个数尽量多,因为m的个数多的话,得到的乘积明显大,现在就是这个r的值,倘若r刚好为0,
则n无多余,则这个乘积一定最大,如果r>0的话
我们只需要通过x+r=l+1 找到x 理由如下
2  3  4  5       1
如果把1加到小的值上 乘积是最大的,3*3*4*5=180;
当加到最大的数上的话  2*3*4*6=144
证明省略 
做一个预处理,求前缀和,和累积
以下有一个有关逆元的 
利用
inv[1]=1;
for(i=2;i<=n;i++)
inv[i]=(mod-mod/i)*inv[mod%i]%mod;求出每个数的逆元

2 3 4 5 6 7 8 9 ......l  +r
b[i]=(b[i-1]*i)%mod;
比如2+r>l
结果只需要ans=b[l]*inv[2]*(2+r);
因为2在做累积进行了取模运算 所以不能直接除2,要乘以她的逆元
 
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<string.h>
#include<map>
#define INF 1000000000
#define LETTER 26
#define SIZE 45000
#define pi 3.14159265358979
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const long long mod=INF+;
int a[SIZE],inv[SIZE];
ll b[SIZE];
int low,high,mid;
void f(){
a[]=;
b[]=;
inv[]=;
for(int i=;i<=SIZE;i++){
a[i]=a[i-]+i;
b[i]=(b[i-]*i)%mod;
inv[i]=(mod-mod/i)*inv[mod%i]%mod; }
}
void erfen(int n){
low=,high=SIZE;
while(low+<high){
mid=(low+high)>>;
if(n>=a[mid]) low=mid;
else high=mid;
}
}
int main(){
int i,j,k;
int t;
int n;
f();
ll ans;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
if(n<=){cout<<n<<endl;continue;}
erfen(n);
int l=low,r=n-a[l];
if(+r>l){
ans=b[l]*inv[]%mod*(+r)%mod;
}
else{
k=l+-r;
ans=b[l]*inv[k]%mod*(l+)%mod;
}
printf("%lld\n",(ans+mod)%mod); } }

hdu 5976 Detachment的更多相关文章

  1. HDU 5976 Detachment(拆分)

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

  2. HDU 5976 Detachment 打表找规律

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

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

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

  4. hdu 5976 Detachment 脑洞题 猜结论

    题目链接 题意 将\(x\)拆成\(a_1+a_2+...+\)的形式,且\(a_1\lt a_2\lt...\),使得\(a_1*a_2*...\)取到最大值 思路 大胆猜结论. 首先拆分的形式中肯 ...

  5. HDU - 5976 Detachment(逆元)

    题意:将一个数x拆成a1+a2+a3+……,ai不等于aj,求最大的a1*a2*a3*……. 分析: 1.预处理前缀和前缀积,因为拆成1对乘积没有贡献,所以从2开始拆起. 2.找到一个id,使得2+3 ...

  6. HDU 5976 数学,逆元

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

  7. HDU 5976 数学

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

  8. hdu5976贪心乘法逆元

    hdu 5976 Detachment题目连接 题意: 给定一个自然数x,让你给出一种拆分方式n=a1+a2+...(ai≠aj),使得每个小部分的乘积s=a1*a2*...最大 解题思路: 我们要乘 ...

  9. 2016ACM/ICPC亚洲区大连站现场赛题解报告(转)

    http://blog.csdn.net/queuelovestack/article/details/53055418 下午重现了一下大连赛区的比赛,感觉有点神奇,重现时居然改了现场赛的数据范围,原 ...

随机推荐

  1. 展开、收起div的jQuery代码

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 使用Docker Image跑Gitlab

    下载gitlab docker镜像 docker pull gitlab/gitlab-ce:latest 启动gitlab服务 sudo docker run --detach \ --hostna ...

  3. sql 事物以及回滚

    第一种: Begin Try    Begin Tran Tran1        insert into t1(Id, c1) values(1,'1')        insert into t1 ...

  4. 安装Linux系统Fedora 23

    搭建了一个Linux(Fedora 23)环境,用于学习.实验. [TOC] 1 安装Fedora 以前一直只会光盘安装,刻录了好多个版本的distros,用完即弃在一旁.很浪费. 此次学会了在Lin ...

  5. 分布式管理系统-git安装及配置

    安装完成后,在开始菜单里找到“Git”->“Git Bash”,蹦出一个类似命令行窗口的东西,就说明Git安装成功! 安装完成后,还需要最后一步设置,在命令行输入: $ git config - ...

  6. Mathmatics

     点 到直线 距离 公式 . 平面内

  7. mouseChildren启示

    将aSprite的 mouseChildren 属性设置为 false ,可以实现mouseClick 事件的目标为 aSprite对象,而不是其子对象中的任一个.

  8. SpringMVC保存数据到mysql乱码问题

    SpringMVC保存数据到mysql乱码问题 乱码问题常见配置 一.web.xml配置过滤器 <filter> <filter-name>encoding-filter< ...

  9. sql server 触发器应用 insert

    --添加自定义错误码提示,要求先有英文版才能有中文版 EXEC sp_addmessage ,,@msgtext='Violation of the table unique constraint', ...

  10. ArcEngine:The XY domain on the spatial reference is not set or invalid错误

    在创建数据集的时候,提示The XY domain on the spatial reference is not set or invalid错误. 原因:未设置空间参考(ISpatialRefer ...