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 ...
随机推荐
- js之 DOM与BOM
JavaScript HTML DOM (文档对象模型)(Document Object Model) 什么是DOM? DOM是W3C标准. DOM定义了访问文档的标准: “W3C文档对象模型(DOM ...
- Redis数据迁移的三个方法
为什么80%的码农都做不了架构师?>>> 1. rdb数据备份恢复方法 redis 127.0.0.1:6379> SAVE OK 或者 redis-cli -h 127. ...
- 你的GitHub,怎么和我用的不太一样?
说起代码托管,相信绝大多数人脑海中浮现出的第一个词都是"GitHub".经过多年的发展,GitHub俨然已经成为了代码托管领域的标签- 随着国内互联网环境的优化,互联网产业链的不断 ...
- Vs Code在Vue项目中v-for指令提示错误的解决办法
最近在做一个Vue项目,在其中用到v-for指令时,发现Vs Code报错,如下图(代码是没有任何问题的),在网上找了一下解决办法,希望能帮助到更多人. 解决方法: 打开 文件-首选项-设置 将 ...
- Codeforce-CodeCraft-20 (Div. 2)-A. Grade Allocation
n students are taking an exam. The highest possible score at this exam is m. Let ai be the score of ...
- Codeforces Round #561 (Div. 2) A. Silent Classroom(贪心)
A. Silent Classroom time limit per test1 second memory limit per test256 megabytes inputstandard inp ...
- UDP广播的客户端和服务器端的代码设计
实验环境 linux 注意: 使用UDP广播,是客户端发送广播消息,服务器端接收消息.实际上是客户端探测局域网中可用服务器的一种手段.客户端发送,服务器端接收,千万不能弄混淆!!! 为了避免混淆,本文 ...
- 【Java8新特性】一张图带你领略Java8有哪些新特性
写在前面 很多小伙伴留言说,冰河你能不能写一些关于Java8的文章呢,看书看不下去,看视频进度太慢.好吧,看到不少读者对Java8还是比较陌生的,那我就写一些关于Java8的文章吧,希望对大家有所帮助 ...
- Datasource Server returns invalid timezone问题
今天在学习一个项目的时候,idea中的datasource没有配置,后来发现mysql没有连接,于是下载了最新版的jdbc.jar包,连接mysql完成后,想test一下mysql connect,结 ...
- LeetCode 刷题1---两数之和
/** 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数组中 ...