BestCoder Round #76 (div.2)
来源:互联网 发布:怎么做淘宝客服怎么找 编辑:程序博客网 时间:2024/05/01 00:24
DZY Loves Partition
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1241 Accepted Submission(s): 463
Total Submission(s): 1241 Accepted Submission(s): 463
思路:假设所给数是a,要分成n个数,最小是从1到n,sum=(1+n)*n/2,if(sum>a)输出-1;
否则一定是可解,假设先分成1~n;cnt(每个数的增量)=(a-sum)/n;j(余下的数)=(a-sum)%n,j分别给倒数j个数分别+1;应为题中说数不能重复。
Problem Description
否则一定是可解,假设先分成1~n;cnt(每个数的增量)=(a-sum)/n;j(余下的数)=(a-sum)%n,j分别给倒数j个数分别+1;应为题中说数不能重复。
Problem Description
DZY loves partitioning numbers. He wants to know whether it is possible to partitionn into the sum of exactly k distinct positive integers.
After some thinking he finds this problem is Too Simple. So he decides to maximize the product of thesek numbers. Can you help him?
The answer may be large. Please output it modulo109+7 .
After some thinking he finds this problem is Too Simple. So he decides to maximize the product of these
The answer may be large. Please output it modulo
Input
First line contains t denoting the number of testcases.
t testcases follow. Each testcase contains two positive integers n,k in a line.
(1≤t≤50,2≤n,k≤109 )
(
Output
For each testcase, if such partition does not exist, please output−1 . Otherwise output the maximum product mudulo 109+7 .
Sample Input
43 43 29 3666666 2
Sample Output
-1224110888111HintIn 1st testcase, there is no valid partition.In 2nd testcase, the partition is $3=1+2$. Answer is $1\times 2 = 2$.In 3rd testcase, the partition is $9=2+3+4$. Answer is $2\times 3 \times 4 = 24$. Note that $9=3+3+3$ is not a valid partition, because it has repetition.In 4th testcase, the partition is $666666=333332+333334$. Answer is $333332\times 333334= 111110888888$. Remember to output it mudulo $10^9 + 7$, which is $110888111$.
Source
BestCoder Round #76 (div.2)
#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#include <queue>#include <iostream>#define LL long long#include <climits>using namespace std;const LL MOD=1e9+7;int main(){ int n; LL a,b; LL sum; cin>>n; while(n--) { cin>>a>>b; sum=(1+b)*b/2; if(sum>a) { printf("-1\n"); } else { a-=sum; LL cnt=a/b; LL j=a%b; LL ans=1; for(LL i=b+cnt;i>=1+cnt;i--,j--) { if(j>0) (ans*=(i+1))%=MOD; else (ans*=(i))%=MOD; } printf("%I64d\n",ans); } } return 0;}
0 0
- BestCoder Round #76 (div.2)
- BestCoder Round #76 (div.2)
- BestCoder Round #76 (div.2)A
- BestCoder Round #11 (Div. 2)
- BestCoder Round #11 (Div. 2)
- BestCoder Round #50 (div.2)
- BestCoder Round #50 (div.2)
- BestCoder Round 50 (div 2)
- BestCoder Round #50 (div.2)
- #BestCoder Round #50 (div.2)
- BestCoder Round #50 (div.2)
- BestCoder Round #54 (div.2)
- BestCoder Round #56 (div.2)
- BestCoder Round #58 (div.2)
- BestCoder Round #59 (div.2)
- BestCoder Round #59 (div.2)
- #BestCoder Round #59 (div.2)
- BestCoder Round #59 (div.2)
- 向上转型和向下转型
- 指针和引用
- Java语法01
- httpclient 4.5.1---连接管理
- OpenGL顶点数据传输速度优化
- BestCoder Round #76 (div.2)
- BZOJ-2659 算不出的算式 找规律找规律找规律(说三遍)
- leatcode 9.Palindrome Number
- Runtime使用场景
- java项目相对路径问题
- APUE之线程(五)
- Spring操作Mongodb
- 数据结构与算法——AVL树简介
- delegate、notification、KVO的使用场景总结