Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

生成函数是王道!

Posted by Ruby931031 at 2012-09-11 19:43:53 on Problem 3734
简单的不能再简单了……
//母函数为G(x) = [ e^(4x) + 2*e^(2x) + 1 ]/4
//易见x^n项的系数为: ( 4^n + 2^(n+1) )/4 = 4^(n-1) + 2^(n-1)
#include <stdio.h>
#define MOD 10007	//已计算过不会发生越界错误

int main(){
	int t,n,a,ans;
	scanf("%d", &t);
	while (t--){
		scanf("%d", &n);
		n = (n-1)%(MOD-1);	//此处应用费马小定理
		ans=1,a=2;
		while (n){	//计算2^n
			if (n&1)		ans = (ans*a)%MOD;
			a = (a*a)%MOD;
			n>>=1;
		}
		ans = ( ans + ans*ans ) % MOD;
		printf("%d\n", ans);
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator