HDU 5976 Detachment
来源:互联网 发布:mysql设置primary key 编辑:程序博客网 时间:2024/05/21 18:35
Detachment
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 207 Accepted Submission(s): 74
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)
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:
1.Two different small line segments cannot be equal (
2.Make this multidimensional space size s as large as possible (s=
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
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
14
Sample Output
4
Source
2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)
Recommend
wange2014 | We have carefully selected several similar problems for you: 5981 5979 5978 5977 5975
考虑到最优解只能是2+3+4+....+n -y==x的情况下。
如果y为0 把1直接加到n上面
如果y为1.1扣掉就好了。。
如果y为2,扣掉2就行了。。然后1加到n上。。
如果y》3 ,从中间扣掉一个y-1 1扣掉就行了。。
因为有除法,,所以先预处理阶层,,,然后瞎几把二分找到 n和y的值。。
取个逆元就行了。
#include<bits/stdc++.h>#include <cstdio>#include <algorithm>using namespace std;typedef long long ll;typedef pair<int,int> pll;const ll mod=1e9+7;ll pow(ll a,ll b,ll c){ ll res=1; while(b) { if(b&1) res=res*a%c; a=a*a%c; b>>=1; } return res;}int main(){ int t; ll fac[100005]; fac[0]=1; for(int i=1; i<=100000; i++) fac[i]=fac[i-1]*i%mod; scanf("%d",&t); while(t--) { ll n; scanf("%lld",&n); if(n==1) { cout<<n<<endl; continue; } ll y; ll m; ll l=0,r=100000; while(l<=r) { ll mid=(l+r)/2; if((mid*(mid+1)/2)>=n) { m=mid; y=m*(m+1)/2-n; r=mid-1; } else l=mid+1; } if(y==0) printf("%lld\n",fac[m+1]*pow(m,mod-2,mod)%mod); else if(y==1) printf("%lld\n",fac[m]%mod); else if(y==2) printf("%lld\n",fac[m+1]*pow(2LL*m,mod-2,mod)%mod); else printf("%lld\n",fac[m]*pow(y-1,mod-2,mod)%mod); } return 0;}
0 0
- HDU 5976 Detachment
- HDU 5976 Detachment
- HDU 5976 Detachment
- hdu 5976 Detachment
- HDU 5976 Detachment
- HDU 5976 Detachment
- HDU 5976 Detachment 逆元
- hdu 5976 Detachment(数论,一个结论)
- hdu 5976 Detachment 逆元+二分+数学
- HDU 5976 Detachment (逆元)
- HDU 5976 Detachment (数学规律+逆元)
- HDU 5976 Detachment(逆元+二分优化+数学分析)
- HDU 5976 Detachment(逆元)+逆元总结
- HDU 5976 && 2016ICPC大连 F: Detachment(找规律)
- hdu 5976 Detachment(乘法逆元)(附测试用例)
- HDOJ 5976 Detachment
- hdoj 5976 Detachment
- Detachment
- C++学习笔记一
- 详细剖析IntentService的运作机理
- 神经网络简介-防止过拟合
- Matlab图形修饰函数
- 输入输出流 I/O
- HDU 5976 Detachment
- enum枚举类
- HTML 实现注册小案例
- 洛谷1613跑路
- 交换a和b的方法讲解
- gnuplot画图中文字体乱码问题
- 在一个集合中存储了无序并且重复的字符串,定义一个方法,让其有序(字典顺序),而且还不能去除重复
- 【python】读取文件&停止启动进程
- 数据结构实验之数组三:快速转置