/*
满足n>=(k+1)*k/2的整数n必定满足 a+(a+1)+...+(a+k-1)<=n<=(a+1)+(a+2)+...+(a+k)
只要在[a,a+k]中减掉一个数字ai,就有n=sum(a,a+k)-ai;且其乘积能达到最大
那么二分先找到a,如果n=sum(a,a+k-1),那么已经是答案了,否则减去那个ai即可
*/
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std; ll n,k; int judge(ll x){
ll tot=(x+x+k-)*k/;
if(tot<n) return ;
return ;
} int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%lld%lld",&n,&k);
if(n<k*(k+)/){
puts("-1");
continue;
} ll ans=,tot=,l=,r=n,mid,a=;
while(l<=r){
mid=l+r>>;
if(judge(mid))
a=mid,l=mid+;
else r=mid-;
}
tot=(a+a+k-)*k/;
if(tot==n){
for(int i=;i<k;i++)
ans=ans*(i+a)%mod;
}
else {
tot+=a+k;
ll tmp=tot-n;
for(int i=a;i<=a+k;i++)
if(i==tmp) continue;
else ans=ans*(ll)i%mod;
}
printf("%lld\n",ans);
}
return ;
}

hdu5646数学构造+二分的更多相关文章

  1. 【BZOJ2876】【NOI2012】骑行川藏(数学,二分答案)

    [BZOJ2876][NOI2012]骑行川藏(数学,二分答案) 题面 BZOJ 题解 我们有一个很有趣的思路. 首先我们给每条边随意的赋一个初值. 当然了,这个初值不会比这条边的风速小. 那么,我们 ...

  2. 【CodeForces】708 B. Recover the String 数学构造

    [题目]B. Recover the String [题意]找到一个串s,满足其中子序列{0,0}{0,1}{1,0}{1,1}的数量分别满足给定的数a1~a4,或判断不存在.数字<=10^9, ...

  3. POJ-2109 Power of Cryptography(数学或二分+高精度)

    题目链接: https://vjudge.net/problem/POJ-2109 题目大意: 有指数函数 k^n = p , 其中k.n.p均为整数且 1<=k<=10^9 , 1< ...

  4. Codeforces 715A. Plus and Square Root[数学构造]

    A. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  5. poj 1905 Expanding Rods (数学 计算方法 二分)

    题目链接 题意:将长度为L的棒子卡在墙壁之间.现在因为某种原因,木棒变长了,因为还在墙壁之间,所以弯成了一个弧度,现在求的是弧的最高处与木棒原先的地方的最大距离. 分析: 下面的分析是网上别人的分析: ...

  6. HDU 2493 Timer 数学(二分+积分)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2493 题意:给你一个圆锥,水平放置,圆锥中心轴与地面平行,将圆锥装满水,在圆锥某一表面开一个小洞,流出来 ...

  7. hdu_2446_Shell Pyramid(数学,二分)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2446 题意:题面很大,有用的就那么几句,意思就是用自然数来堆它画的那个金字塔,比如第一个金字塔的第一个 ...

  8. 2017广东工业大学程序设计竞赛初赛 题解&源码(A,水 B,数学 C,二分 D,枚举 E,dp F,思维题 G,字符串处理 H,枚举)

    Problem A: An easy problem Description Peter Manson owned a small house in an obscure street. It was ...

  9. Really Big Numbers CodeForces - 817C (数学规律+二分)

    C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...

随机推荐

  1. 深入理解 BFC

    W3C 规范中 BFC的定义: 浮动元素和绝对定位元素,非块级盒子的块级容器(例如 inline-blocks, table-cells, 和 table-captions),以及overflow值不 ...

  2. c# 打印 bartender

    参考: 官网  https://www.seagullscientific.com/label-software/barcode-label-design-and-printing 文章 http:/ ...

  3. Catfish CMS漏洞集合

    转自https://larryxi.github.io/ 0x00 背景 版本:V 4.2.35 官网下载:http://www.catfish-cms.com/page/4.html 文章内容仅作学 ...

  4. Linux - 日志处理一

    Linux 日志处理 history # 历时命令默认1000条 HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S " # 让history命令显示具体时间 hi ...

  5. slice() 和splice()

    splice() 方法与 slice() 方法的作用是不同的,splice() 方法会直接对数组进行修改. 1, splice() 方法向/从数组中添加/删除项目,然后返回被删除的项目. splice ...

  6. 在使用kvc进行赋值的时候,有时候会遇到null值,这个时候我们使用kvc会报错

    在使用kvc进行赋值的时候,有时候会遇到null值,这个时候我们使用kvc会报错,如何解决 控制器代码如下: // // ViewController.m // 02-模型中的赋值 // // Cre ...

  7. python正则表达式一[转]

    原文:http://blog.jobbole.com/74844/ 作为一个概念而言,正则表达式对于Python来说并不是独有的.但是,Python中的正则表达式在实际使用过程中还是有一些细小的差别. ...

  8. JS如何防止事件冒泡

    <div style="height:30px;line-height:30px;background:#FF0;text-align:center;" id="z ...

  9. 【Shell】带颜色输出(白底x色)

    echo -e "\033[31mHello World.\033[0m" 红色31m 绿色32m 黄色33m 蓝色34m 黑色30m 白色37m 紫色35m 深绿色36m

  10. T_RegionNDS表创建及值

    -- Table structure for t_regionnds -- ---------------------------- DROP TABLE IF EXISTS t_regionnds; ...