"bzoj4591" [Shoi2015] super-energy particle cannon-Modified Lucas theorem _ number theory

Source: Internet
Author: User

Lucas theorem
Ans=c (n,0) +c (n,1) +......+c (n,k)
=c (n/2333,0) *c (n%2333,0) +c (n/2333,0) *c (n%2333,1) +......+c (n/2333,0) *c (n%2333,2332) +c (/2333,1) *C (n%2333,0) +......+C (n/) 2333,k/2333) * (n%2333,k%2333)

=∑c (N/2333,J) *sum[n%2333][2332] (0<=j<k/2333) +c (n/2333,k/2333) *sum[n%2333][k%2333]

Cal (N,k) =cal (n/2333,k/2333-1) *sum[n%2333][2332]+lucas (n/2333,k/2333) *sum[n%2333][k%2333]

Attention to prefix and processing

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
# include<algorithm>
#include <iostream>
#define MOD 2333

using namespace std;

int T;
Long long c[mod][mod],sum[mod][mod];

Long Long Lucas (long long X,long long y)
	if (x<y | | | y<0) return 0; 
	if (x<mod && y<mod) return c[x][y];
	Return Lucas (X/mod,y/mod) *c[x%mod][y%mod]%mod;

Long Long cal (Long long N,long long k)
	if (k<0) return 0;
	Return (Cal (n/mod,k/mod-1) *sum[n%mod][mod-1]+lucas (n/mod,k/mod) *sum[n%mod][k%mod])%mod;

int main ()
	for (int i=1;i<mod;i++) sum[0][i]=1;
	for (int i=1;i<mod;i++)
		for (int j=1;j<=i;j++) c[i][j]= (c[i-1][j-1]+c[i-1][j])%mod;
		for (int j=1;j<mod;j++) sum[i][j]= (sum[i][j-1]+c[i][j])%mod;
	scanf ("%d", &t);
	while (t--)
		long long n,k;
		scanf ("%lld%lld", &n,&k);
		printf ("%lld\n", Cal (N,k));
	return 0;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: