BC Round #76 HDU 5646(数学)

来源:互联网 发布:网络文化传媒公司 编辑:程序博客网 时间:2024/05/17 10:55
//  方法:BC官网有 链接:http://bestcoder.hdu.edu.cn 
//  main.c//  example////  Created by Adam on 15/2/2.//  Copyright (c) 2015年 Adam. All rights reserved.//////  main.c//  example////  Created by Adam on 15/2/2.//  Copyright (c) 2015年 Adam. All rights reserved.//#include <algorithm>#include <iostream>#include <string.h>#include <stdlib.h>#include <stdio.h>using namespace std;long long mod=1000000007;int cal(double n, double k){    return (int)((n - (k * k - k)/2) /k);}long long sum(int a, int k){    return 1ll * (a + a + k - 1) * k / 2;}int main(){    int t;    scanf("%d", &t);    while(t--)    {        int n, k;        scanf("%d%d", &n, &k);        if(sum(1,k) > n) {            printf("-1\n");            continue;        }        int pos = cal(n, k);              long long int ans = 1;        int u = n - sum(pos, k);        for(int i = 1; i <= k - u; i++)            ans = (ans * (i + pos - 1)) % mod;        for(int i = k - u + 1; i <= k; i++)            ans = (ans * (i + pos)) % mod;        printf("%lld\n", ans);    }    return 0;}

0 0