hdu 5976 Detachment
Detachment
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 392 Accepted Submission(s):
131
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 ( aiaj
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)
test cases.
Then T lines follow. Each line contains one integer
x.
1≤T≤10^6, 1≤x≤10^9
to be greatest product before modulo 10^9+7.
4
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的更多相关文章
- HDU 5976 Detachment(拆分)
HDU 5976 Detachment(拆分) 00 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem D ...
- HDU 5976 Detachment 打表找规律
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5976 Detachment Time Limit: 4000/2000 MS (Java/Other ...
- HDU 5976 Detachment 【贪心】 (2016ACM/ICPC亚洲区大连站)
Detachment Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu 5976 Detachment 脑洞题 猜结论
题目链接 题意 将\(x\)拆成\(a_1+a_2+...+\)的形式,且\(a_1\lt a_2\lt...\),使得\(a_1*a_2*...\)取到最大值 思路 大胆猜结论. 首先拆分的形式中肯 ...
- HDU - 5976 Detachment(逆元)
题意:将一个数x拆成a1+a2+a3+……,ai不等于aj,求最大的a1*a2*a3*……. 分析: 1.预处理前缀和前缀积,因为拆成1对乘积没有贡献,所以从2开始拆起. 2.找到一个id,使得2+3 ...
- HDU 5976 数学,逆元
1.HDU 5976 Detachment 2.题意:给一个正整数x,把x拆分成多个正整数的和,这些数不能有重复,要使这些数的积尽可能的大,输出积. 3.总结:首先我们要把数拆得尽可能小,这样积才会更 ...
- HDU 5976 数学
Detachment Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu5976贪心乘法逆元
hdu 5976 Detachment题目连接 题意: 给定一个自然数x,让你给出一种拆分方式n=a1+a2+...(ai≠aj),使得每个小部分的乘积s=a1*a2*...最大 解题思路: 我们要乘 ...
- 2016ACM/ICPC亚洲区大连站现场赛题解报告(转)
http://blog.csdn.net/queuelovestack/article/details/53055418 下午重现了一下大连赛区的比赛,感觉有点神奇,重现时居然改了现场赛的数据范围,原 ...
随机推荐
- c++ 11 sleep()
#include<chrono>#include<thread> std::this_thread::sleep_for(std::chrono::milliseconds(1 ...
- C#检测键盘输入
void Update(){ if (Input.GetKey(KeyCode.W)) { go stread; } if (Input.GetKey ...
- TStringList的bug问题
今天测试发现用TStringList进行字符分隔的时候 ,如果被分隔对象中含有空格就有产生发隔错误 方案一:可以用其它的函数来代替 方案二:Items.StrictDelimiter:= True;
- oracle sql改写
or可以改写成union 但是要注意,改写成union的时候一定要有一个唯一列参照,不然会少记录,因为union会去重. 可以用的唯一列:唯一索引列,主键列,rowid,rownum(视图里用这个)
- 使用Goertzel算法识别DTMF信号
Goertzel算法 Goertzel算法由Gerald Goertzel在1958年提出,用于数字信号处理,是属于离散傅里叶变换的范畴,目的是从给定的采样中求出某一特定频率信号的能量,用于有效性的评 ...
- xcode的类库报错,如何解决
首先看一下自己报错的原因,是当前UIkit框架还是别的,然后按住Command+shift+G 把"/Applications/Xcode.app/Contents/Developer/Pl ...
- iOS启动页设置
点击项目->TARGETS->App Icons and Launch Images->Launch Images Source->Use Asset Catalog...-& ...
- HFSS设计导入AD中
具体过程有些繁琐,录制了一个视频放在百度网盘了.亲测有效. 网盘地址:http://pan.baidu.com/s/1gfIBhC3 密码:ayoa
- Web应用定时任务实现
一.需求: 项目上有时需要执行一些定时任务,比如:超过2天未处理的问题,邮件自动通知客服.对接人:3天未处理的问题,邮件自动通知客服.对接人和项目经理,同时标为‘紧急’状态:5天未处理的问题,邮件自动 ...
- asp.net mvc表单异步提交
html代码: @using (Html.BeginForm("xx", "xx", FormMethod.Post, new { enctype = &quo ...