Detachment

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

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<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+;
const int mod=1e9+;
long long add[N],mul[N];
void init(){
add[]=add[]=;
mul[]=mul[]=;
for(int i=;i<N;++i) {
add[i]=i+add[i-];
mul[i]=(mul[i-]*i)%mod;
}
}
long long kuai(long long base,long long k){
long long ans=;
while(k){
if(k&) ans=(ans*base)%mod;
k>>=;
base=(base*base)%mod;
}
return ans;
}
int main(){
init();
int T;
for(scanf("%d",&T);T--;){
int x;
scanf("%d",&x);
if(x<=) {printf("%d\n",x);continue;}
int l=,r=N-,ans;
while(l<=r){
int mid=(l+r)>>;
if(add[mid]<=x) {ans=mid,l=mid+;}
else r=mid-;
}
int temp=x-add[ans];
if(temp==) printf("%I64d\n",mul[ans]);
else if(temp == ans) printf("%I64d\n", mul[ans]*kuai(, mod-)%mod*(ans+)%mod);
else printf("%I64d\n",((mul[ans+]*mul[ans-temp])%mod*kuai(mul[ans-temp+],mod-))%mod);
}
}

http://blog.csdn.net/chen_ze_hua/article/details/53081001  逆元模板

 

hdu5967数学找规律+逆元的更多相关文章

  1. # E. Mahmoud and Ehab and the xor-MST dp/数学+找规律+xor

    E. Mahmoud and Ehab and the xor-MST dp/数学/找规律 题意 给出一个完全图的阶数n(1e18),点由0---n-1编号,边的权则为编号间的异或,问最小生成树是多少 ...

  2. Harmonic Number (II) 数学找规律

    I was trying to solve problem '1234 - Harmonic Number', I wrote the following code long long H( int  ...

  3. 2018icpc南京现场赛-G Pyramid(打标找规律+逆元)

    题意: 求n行三角形中等边三角形个数,图二的三角形也算. n<=1e9 思路: 打表找下规律,打表方法:把所有点扔坐标系里n^3爆搜即可 打出来为 1,5,15,35,70,126,210.. ...

  4. 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

    题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...

  5. UVA 12683 Odd and Even Zeroes(数学—找规律)

    Time Limit: 1000 MS In mathematics, the factorial of a positive integer number n is written as n! an ...

  6. HDU 5914 Triangle 数学找规律

    Triangle 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Description Mr. Frog has n sticks, who ...

  7. ural 2029 Towers of Hanoi Strike Back (数学找规律)

    ural 2029 Towers of Hanoi Strike Back 链接:http://acm.timus.ru/problem.aspx?space=1&num=2029 题意:汉诺 ...

  8. HDU 1273 漫步森林(数学 找规律)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1273 漫步森林 Time Limit: 2000/1000 MS (Java/Others)    M ...

  9. SGU 105 数学找规律

    观察一下序列,每3个数一组,第一个数余1,不能,加第二个数后整除(第二个数本身余2),第三数恰整除.一行代码的事.011011011.... #include<iostream> usin ...

随机推荐

  1. C++编程入门题目--No.3

    题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少? 程序分析: 在10万以内判断,先将该数加上100后再开方,再将该数加上268后再开方,如果开方后 的结 ...

  2. javaweb系统调优方案

    1. java代码优化 java代码优化6大原则 : https://blog.csdn.net/bunny1024/article/details/72803708 java代码优化: https: ...

  3. redis系列之5----redis实战(redis与spring整合,分布式锁实现)

    本文是redis学习系列的第五篇,点击下面链接可回看系列文章 <redis简介以及linux上的安装> <详细讲解redis数据结构(内存模型)以及常用命令> <redi ...

  4. CSS躬行记(9)——网格布局

    网格布局(Grid Layout)也叫栅格布局,与表格布局类似,也依赖行和列.但与之不同的是,网格布局能直接控制HTML文档中元素的顺序.位置和大小等,而不用再借助辅助元素. 一.术语 下图展示了CS ...

  5. 选择结构(if、switch)

    3.2  用if语句实现选择结构 什么是选择结构 单分支if语句 双分支if语句 多分支if语句 1.什么是选择结构? 选择结构又称为分支结构,是根据给定的条件是否成立来决定程序的执行流程. 用if语 ...

  6. GUI_DOWNLOAD 下载乱码

    状况: 开发者打开正常,跨公司或跨企业打开异常. 跨App上传格式异常. 解决上述问题步骤: 1.用浏览器或可改变文件编码格式切换的软件打开文件(其他app上传正常文档格式,或跨公司打开正常文件)查看 ...

  7. 排序算法整理(Python实现)

    目录 1. 冒泡排序 2. 选择排序 3. 插入排序 4. 归并排序 5. 快速排序 1. 冒泡排序   冒泡排序(Bubble Sort)是稳定排序,其基本思想是:遍历待排序列,依次两两比较,如果顺 ...

  8. 自动化测试工具-Selenium IDE 教程一

    引言:这里介绍的是谷歌浏览种的插件,安装教程这里不再描述,网上有很多, 使用教程不是特别多,所以特地花时间整理此篇内容: 一:打开插件,欢迎界面 启动IDE后,将显示一个欢迎对话框. 如果这是您第一次 ...

  9. python3语法学习第四天--序列

    序列是Python中最基本的数据结构. 序列中的每个元素都分配一个索引从0开始依此类推. Python有6个序列的内置类型,但最常见的是列表和元组. 序列可以的操作:索引,切片,加,乘,检查成员. 此 ...

  10. python语法学习第一天--变量、运算符、数据类型

    变量:计算机中的一块内存,给变量赋值意味着将值存入内存中 python中变量不用类型声明(根据赋的值决定类型),但使用时(创建时)必须赋值(=赋值). 多个变量的赋值: ①a=b=c=1; ②a,b, ...