hdu5967数学找规律+逆元
Detachment
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1686 Accepted Submission(s): 467
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
#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数学找规律+逆元的更多相关文章
- # E. Mahmoud and Ehab and the xor-MST dp/数学+找规律+xor
E. Mahmoud and Ehab and the xor-MST dp/数学/找规律 题意 给出一个完全图的阶数n(1e18),点由0---n-1编号,边的权则为编号间的异或,问最小生成树是多少 ...
- Harmonic Number (II) 数学找规律
I was trying to solve problem '1234 - Harmonic Number', I wrote the following code long long H( int ...
- 2018icpc南京现场赛-G Pyramid(打标找规律+逆元)
题意: 求n行三角形中等边三角形个数,图二的三角形也算. n<=1e9 思路: 打表找下规律,打表方法:把所有点扔坐标系里n^3爆搜即可 打出来为 1,5,15,35,70,126,210.. ...
- 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight
题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...
- 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 ...
- HDU 5914 Triangle 数学找规律
Triangle 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Description Mr. Frog has n sticks, who ...
- ural 2029 Towers of Hanoi Strike Back (数学找规律)
ural 2029 Towers of Hanoi Strike Back 链接:http://acm.timus.ru/problem.aspx?space=1&num=2029 题意:汉诺 ...
- HDU 1273 漫步森林(数学 找规律)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1273 漫步森林 Time Limit: 2000/1000 MS (Java/Others) M ...
- SGU 105 数学找规律
观察一下序列,每3个数一组,第一个数余1,不能,加第二个数后整除(第二个数本身余2),第三数恰整除.一行代码的事.011011011.... #include<iostream> usin ...
随机推荐
- git常用命令/git 部分高级命令备忘录
常用命令 克隆 - git clone git@gitee.com:niunafei1/git_learning.git git 创建分支 - git checkout -b dev git 切换分 ...
- awk和sed命令
awk awk是一个强大的编辑工具,可以在无交互的情况下实现相当复杂的文本操作 awk是行处理器: 相比较屏幕处理的优点,在处理庞大文件时不会出现内存溢出或是处理缓慢的问题,通常用来格式化文本信息 a ...
- windows服务程序的编写
服务编写https://blog.csdn.net/lanuage/article/details/77937407 #include <windows.h> #include <s ...
- Xapian实战(二):core concepts
参考资料 core concepts 正文 1. 并发性 xapian不包含任何全局变量,所以多线程编程中,在没有共享资源的情况下可以安全使用xapian.在实际操作中,由于每个线程都可以创建自己的x ...
- JAVA连接Excel最好用的开源项目EasyExcel,官方使用文档及.jar包下载
EasyExcel是一个基于Java的简单.省内存的读写Excel的开源项目.在尽可能节约内存的情况下支持读写百M的Excel. github地址:https://github.com/alibaba ...
- HDU 1233 最小生成树模板题,练练模板
还是畅通工程 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- Visual Studio Code 缩放设置
Windows下的软件的操作都很类似,所以刚开始使用vs code的时候习惯性地使用Ctrl+鼠标滚轮进行缩放,然而在vs code上不管用. 在vs code中有两类缩放: 一.整体缩放:包括菜单栏 ...
- 题目分享N
题意:有辆车,有r行,s*2列,在第s列和第s+1列之间有个过道,出口在第r+1行的过道处,现在给出每个人的位置(行号和列号),每人每次只能动一格,问最少耗费多长时间全员才能逃出去 分析:假如车上只有 ...
- 再谈 PHP 未来之路
前段时间我写过一篇博文<phper:敢问路在何方>,分析了 PHPer 的困境以及 PHP 程序员的学习.进阶突破之路.同时我在知乎上也发过类似的提问.从大家的评论和回答看,大体分为以下几 ...
- libevent(十)bufferevent 2
接上文libevent(九)bufferevent 上文主要讲了bufferevent如何监听读事件,那么bufferevent如何监听写事件呢? 对于一个fd,只要它的写缓冲区没有满,就会触发写事件 ...