DZY Loves Partition HDU - 5646 思维构造

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int maxn = 305;
int main()
{
	int T;
	ll n,k;
	ll t;
	cin>>T;
	//拆成连续的数,然后加上倍数,再从后往前加剩余的 
	while(T--)
	{
		cin>>n>>k;
		if(k%2) 
			t = (ll)(k+1)/2*k;
		else 
			t = (ll)k/2*(k+1);
		if(t > n)
		{
			printf("-1\n");
			continue ;
		}
		else
		{
			ll po = n-t;
			ll bei = po/k;
			ll els = po%k;
			ll ans = 1;
			for(ll i = k; i >= 1; i--)
			{
				ll cur = i+bei;
				if(els)
				{
					cur++;
					els --;
				}
				ans = (ll)ans*cur%MOD;
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}
posted @ 2020-05-07 16:34  晴屿  阅读(115)  评论(0编辑  收藏  举报