hdu 2065(泰勒展式)
2024-08-20 05:19:39
比赛的时候遇到这种题,只能怪自己高数学得不好,看着别人秒。。。。
由4种字母组成,A和C只能出现偶数次。
构造指数级生成函数:(1+x/1!+x^2/2!+x^3/3!……)^2*(1+x^2/2!+x^4/4!+x^6/6!……)^2.
前面是B和D的情况,可以任意取,但是相同字母一样,所以要除去排列数。后者是A和C的情况,只能取偶数个情况。
根据泰勒展开,e^x在x0=0点的n阶泰勒多项式为 1+x/1!+x^2/2!+x^3/3!……
而后者也可以进行调整,需要把奇数项去掉,则e^(-x)的展开式为1-x/1!+X^2/2!-X^3/3!……
所以后者可以化简为(e^x+e^(-x))/2。则原式为 (e^x)^2 * ((e^x*e^(-x))/2)^2
整理得到e^4x+2*e^2x+1。
又由上面的泰勒展开
e^4x = 1 + (4x)/1! + (4x)^2/2! + (4x)^3/3! + ... + (4x)^n/n!;
e^2x = 1 + (2x)/1! + (2x)^2/2! + (2x)^3/3! + ... + (2x)^n/n!;
对于系数为n的系数为(4^n+2*2^n)/4=4^(n-1)+2^(n-1);
快速幂搞之。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
#define LL long long
#define MOD 100
#define eps 1e-6
#define N 100010
#define zero(a) fabs(a)<eps
using namespace std;
int PowMod(int a,LL b){
int ret=;
while(b){
if(b&)
ret=(ret*a)%MOD;
a=(a*a)%MOD;
b>>=;
}
return ret;
}
int main(){
int t;
while(scanf("%d",&t)!=EOF&&t){
int cas=;
LL n;
while(t--){
scanf("%I64d",&n);
printf("Case %d: %d\n",++cas,(PowMod(,n-)+PowMod(,n-))%MOD);
}
printf("\n");
}
return ;
}
最新文章
- 浅析String、StringBuffer、StringBuilder的区别以及性能区别
- Oracle 11g 数据库自动备份执行脚本
- 使用thinkphp连接sqlserver数据库时提示“系统不支持:sqlsrv”
- 数据结构-多级指针单链表(C语言)
- scrapy shell 中文网站输出报错.记录.
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(2)-easyui构建前端页面框架[附源码]
- 首页 导航栏隐藏 下一级页面显示,pop回来遇到的问题
- Spark SQL Catalyst源代码分析之TreeNode Library
- String,StringBuffer与StringBuilder差异??
- Spring实战——缓存
- SSH key introduction
- 基于flash的web视频对讲直播测试
- Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(待完成)
- linux bash timeout
- win 10 kms 激活 后 火狐 上 https 网站 报错
- js对象(BOM部分/DOM部分)
- Nginx 配置 Location 规则优先级问题
- Spring中IOC与DI的的区别
- sicily 1009. Mersenne Composite N
- BZOJ4567 [Scoi2016]背单词 【trie树 + 贪心】