HDU 5976 数学
Detachment
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1868 Accepted Submission(s): 522
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)
Then T lines follow. Each line contains one integer x.
1≤T≤10^6, 1≤x≤10^9
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 数学的更多相关文章
- HDU 5976 数学,逆元
1.HDU 5976 Detachment 2.题意:给一个正整数x,把x拆分成多个正整数的和,这些数不能有重复,要使这些数的积尽可能的大,输出积. 3.总结:首先我们要把数拆得尽可能小,这样积才会更 ...
- HDU 5984 数学期望
对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...
- 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 2451 数学
Simple Addition Expression Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- [ An Ac a Day ^_^ ] hdu 4565 数学推导+矩阵快速幂
从今天开始就有各站网络赛了 今天是ccpc全国赛的网络赛 希望一切顺利 可以去一次吉大 希望还能去一次大连 题意: 很明确是让你求Sn=[a+sqrt(b)^n]%m 思路: 一开始以为是水题 暴力了 ...
- hdu 4506(数学,循环节+快速幂)
小明系列故事——师兄帮帮忙 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- hdu 4432 数学杂题
http://acm.hdu.edu.cn/showproblem.php?pid=4432 6分钟写的代码,一上午去调试,, 哎,一则题目没看懂就去写了,二则,哎,,恶心了.在坚持几天然后ACM退役 ...
随机推荐
- ie启动不了的解决办法,win7,win8都可以
今天我的IE也无法打开了,我装的是win7的系统,ie升级到了IE11,无法打开了,看到下面这篇文章,借鉴试试,没想到也成功了. 按以上步骤,打开注册表, 第一步.按下Win+R组合键,在出现的运行命 ...
- 【BUG】插入或者更新超过限制后写入数据库失败
Error Code: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your ...
- LVS-NAT搭建HTTP及HTTPS
author:JevonWei 版权声明:原创作品 搭建NAT模式的HTTP环境 网络拓扑图如下 网络环境 RS1 192.168.198.138 RS2 192.168.198.120 LVS: D ...
- C#格式符
在输出字符串时,使用格式说明 使字符串显示适当的格式,比如:货币格式,或者科学计数法.百分比等. 以下是格式化的数字字符串 格式. {index, alignment: format} 例如: ; ...
- HashMap 底层算法分析
详见: http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp72 Hash算法HashMap使用Hash算法,所以在解剖HashMap ...
- Swiper+JS 上拉刷新
JS // 上拉刷新 var page = 2; var isAjax = true;//加载数据前状态 $( ...
- Linux下设置Tomcat虚拟路径
问题描述:我在上传图片的位置不在Tomcat服务器下,用户无法访问 解决方案:配置Tomcat虚拟路径使用户可以访问图片 配置Tomcat # cd /usr/local/apache-tomcat- ...
- linux命令每日一练:find与rm实现查找并删除目录或文件
linux命令每日一练 linux中find与rm实现查找并删除目录或文件 linux 下用find命令查找文件,rm命令删除文件. 删除指定目录下指定文件 find 要查找的目录名 -name .s ...
- 软工+C(2017第4期) Alpha/Beta换人
// 上一篇:超链接 // 下一篇:工具和结构化 注:在一次软件工程讨论课程进度设计的过程中,出现了这个关于 Alpha/Beta换人机制的讨论,这个机制在不同学校有不同的实施,本篇积累各方观点,持续 ...
- 团队作业4——第一次项目冲刺(Alpha版本)
Deadline: 2017-4-30 22:00PM,以博客发表日期为准 评分基准: 按时交 - 有分,检查的项目包括后文的两个个方面 七天的敏捷冲刺 日志的集合贴 晚交 - 0分 迟交一周以上 - ...