hdu 4549——M斐波那契数列

手把手教你用Microsoft AEC Challenge数据集训练自己的回声消除模型(附完整代码) 本文详细介绍了如何使用Microsoft AEC Challenge数据集训练专业的回声消除模型,包括环境准备、数据清洗、模型架构设计、训练流程和实际部署注意事项。通过完整的代码示例和实战指南,帮助开发者快速掌握AEC技术,提升语音通信系统的回声消除效果。 阅读详情

矩阵快速幂+欧拉定理


#include<iostream>
#include<cstring>
using namespace std;
#define mod 1000000007
#define LL __int64
void Mul(LL a[2][2],LL b[2][2],LL c[2][2])//矩阵的乘法运算
{
	int i,j,k;
	LL sum;
	for(i=0;i<2;i++)
		for(j=0;j<2;j++)
		{
			sum=0;
			for(k=0;k<2;k++)
				sum+=(a[i][k]*b[k][j])%(mod-1);
			c[i][j]=sum%(mod-1);
		}
}
void Pow(LL a[2][2],LL n)
{
	if(n==1)
		return ;
	LL b[2][2],c[2][2];
	memcpy(b,a,sizeof(b));
	Pow(b,n/2);//n的最后一位是1,举个例子说明a^11101=a^( (1110*2) +1)=(a^1110)*(a^1110)*a
	if(n&1)
	{
		Mul(b,a,c);
		Mul(c,b,a);
	}	
	else
		Mul(b,b,a);

}
LL getsum(LL n)
{
	LL a[2][2]={//初始化矩阵
		{1,1},
		{1,0}
	};
	if(n==0)
		return 0;
	else
	{
		Pow(a,n);
		return a[0][1]%(mod-1);
	}
	
}
LL pow(LL a,LL k)
{
	if(k==1)
		return a;
	if(k==0)
		return 1;
	LL c=pow(a,k>>1);
	if(k%2==0)
		return c*c%mod;
	else
		return c*c%mod*a%mod;
}
int main()
{
	LL a,b,n;
	while(cin>>a>>b>>n)
	{
		if(n==0)
		{
			printf("%I64d\n",a%mod);
			continue;
		}
		if(n==1)
		{
			printf("%I64d\n",b%mod);
			continue;
		}
		
		printf("%I64d\n",(pow(a,getsum(n-1)) *pow(b,getsum(n)))%mod );
	}
	return 0;
}


别再死记硬背了!用Multisim仿真5分钟搞懂运放电压跟随器到底要不要加反馈电阻 本文通过Multisim仿真实验,深入解析运放电压跟随器中反馈电阻的必要性。实验对比不同阻值对电路性能的影响,揭示反馈电阻在提供偏置电流通路、提升高频稳定性和ESD保护中的关键作用,并给出工程实践中的优化建议,帮助工程师快速掌握运放电路设计要点。 阅读详情

相关推荐

OpenBmc开发2:构建开发环境

编译环境VMware + ubuntu 18.04 编译环境构建:参考OpenBmc开发1:构建开发环境 1、打开一个Ternimal,进入openbmc目录下 2、查看有哪些不同的编译配置 find meta-* -name local.conf.sample 可以看到如下编译配置 3、生成编译配置 插入TEMPLATECONF,上边查询到的配置有很多,但是有一些...

master 2万+

HDU4549(欧拉函数+快速幂)

M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 560    Accepted Submission(s): 156 Problem Description M斐波那契数列F[n]是一种整数数列,它的定

晓风残月xj 1278

避坑指南:PVE下N卡直通错误代码43的终极解决思路与dmesg日志分析

本文详细解析了PVE环境下NVIDIA显卡直通时遇到的错误代码43问题,提供了从dmesg日志分析到BIOS配置、PVE宿主机优化及虚拟机设置的完整解决方案。特别针对GTX1060等显卡,分享了驱动版本选择、ROM修补及高级排错技巧,帮助用户彻底解决这一常见难题。

weixin_28693683的博客 299

hdu4549---M斐波那契数列(矩阵+欧拉定理)

Problem Description M斐波那契数列F[n]是一种整数数列,它的定义如下:F[0] = a F[1] = b F[n] = F[n-1] * F[n-2] ( n > 1 )现在给出a, b, n,你能求出F[n]的值吗?Input 输入包含多组测试数据; 每组数据占一行,包含3个整数a, b, n( 0 <= a, b, n <= 10^9 )Output 对每组测试

Alex 1125

微信小程序协同工作和发布

微信小程序协同工作和发布

qq_53114527的博客 1625

ThingsBoard入门实战(七):公共发布和 UI 细节修改

公共发布和 UI 细节修改7.细节修改和公共发布一、公共发布二、UI优化下载运行修改三、下一步还可以做什么?更好的UI更丰富的系统模块 7.细节修改和公共发布 GET到新技能了,想给兄弟们演示,需要给他们每个人一个账号么? 答案肯定是:不需要! ThingsBoard 用 公共发布 解决了这个问题。 一、公共发布 首先我们来看一下路灯设备现在在谁名下? 如下图,路灯都是customerA的, 目前只有它和它的租户可以看到,其他人需要看就需要设为公有。 如图操作: 对于设备详情仪表盘,我们也需要设为公有

AIGC搞起 9133

HDU - 4549 斐波那契数列 (费马小定理+快速幂矩阵)

题意: 你会发现a和b的指数变化就是斐波那契数列,再结合费马小定理,定理应用到这一题就是可以将(A^B)%mod = (A^(B % mod ) )% mod)。 注意:用 long long防止数据溢出,最后a,b相乘之后要再取一次模。 #include #include #include #include #include #include using namespace std; #d

blaze_jack 378

让 PyCharm 代码“发光”:高亮插件与特效全攻略

PyCharm 作为一款强大的 Python IDE,支持多种插件让代码“发光”——无论是动态输入特效、彩虹括号,还是霓虹主题,都能让你的代码脱颖而出!进入 File → Settings → Editor → Color Scheme → Rainbow Brackets。进入 File → Settings → Appearance & Behavior → Material Theme。进入 File → Settings → Editor → Color Scheme → General。

qq_43580271的博客 3848

HDU-4549(矩阵快速幂+欧拉定理)

题意: F[0] = a, F[1] = b  F[n] = F[n-1] * F[n-2] (n > 1)  现在给出a, b, n,你能求出F[n]的值吗? 思路: 将F[n]推到F[0], F[1]可发现F[n]能表示成两个连续斐波那契数次幂的F[0]和F[1]的乘积:F[n] = F[0]^(n-1)*F[1]^(n)。矩阵快速幂求出斐波那契数, 然后普通快速幂求出F[n

yo_bc的博客 701

Autosar EcuM配置-初始化及下电执行函数-基于ETAS软件

Autosar EcuM学习笔记-上电初始化执行函数及下电前执行函数,本文介绍在EcuM中的配置及使用。

赞的博客 858

「深度学习之优化算法」(五)差分进化算法

每次迭代将先进行变异操作,选择一个或多个个体的基因作为基,然后选择不同的个体的差分来构成差分基因,最后将作为基的基因与差分基因相加来得出新的个体。,大喊一声,进化吧,魔王兵i的基因改变了。交叉率CR,影响基因取自变异基因的比例,由于至少要保留一位自己的基因和变异的基因导致CR在该问题上对算法性能的影响不大(这个问题比较简单,维度较低,影响不大)。与遗传算法同为进化算法的差分进化算法,它们的操作(算子)也都非常相似的,都是交叉,变异和选择,流程也几乎一样(遗传算法先交叉后变异,差分进化算法先变异后交叉)。

quanzhan_King的博客 1507

hdu-4549(矩阵快速幂+欧拉定理)

问题描述: M斐波那契数列F[n]是一种整数数列,它的定义如下:  F[0] = a  F[1] = b  F[n] = F[n-1] * F[n-2] ( n > 1 )  现在给出a, b, n,你能求出F[n]的值吗? Input 输入包含多组测试数据;  每组数据占一行,包含3个整数a, b, n( 0 Output 对每组测试数据请输出一个整

wust_cyl的博客 484

【AUTOSAR-CanNM】-3.1-如何让ECU发出的首帧是NM帧(Tx Nm报文先于Tx App应用报文发出)

如何让ECU发出的首帧是NM帧(Tx Nm报文先于Tx App应用报文发出)

「汽车电子助手」的博客 4732

M斐波那契数列 HDU - 4549

M斐波那契数列 HDU - 4549 思路:题意很简单,但是不好写,如果不知道幂的取模的话,基本就是tle。要知道如下定理:当m为素数,且a、m互质时, a^n % m = a^(n%(m-1)) % m。取模的问题解决了,就是矩阵快速幂了。 #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; us...

DeathYmz的博客 688

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

HDU 4549 M斐波那契数列

M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 5790    Accepted Submission(s): 1801   Problem Description M斐波那契数列F[n]是一种整数数列,它的定义如下...

~ 518

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

【hdu 4549】 M斐波那契数列

Problem DescriptionM斐波那契数列F[n]是一种整数数列,它的定义如下:F[0] = aF[1] = bF[n] = F[n-1] * F[n-2] ( n &gt; 1 )现在给出a, b, n,你能求出F[n]的值吗? Input输入包含多组测试数据;每组数据占一行,包含3个整数a, b, n( 0 &lt;= a, b, n &lt;= 10^9 ) Output对每组测试...

TLECODE的博客 437

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

hdu 4549 M斐波那契数列 数论 矩阵

M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 724    Accepted Submission(s): 206 Problem Description M斐波那契数列F[n]是一种整数数列,它的定义如

hnust_xiehonghao的专栏 4624

M斐波那契数列(HDU-4549)

Problem Description M斐波那契数列F[n]是一种整数数列,它的定义如下: F[0] = a F[1] = b F[n] = F[n-1] * F[n-2] ( n > 1 ) 现在给出a, b, n,你能求出F[n]的值吗? Input 输入包含多组测试数据; 每组数据占一行,包含3个整数a, b, n( 0 <= a, b, n <= ...

Alex_McAvoy的博客 756

hdu 4549 M斐波那契数列

M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 2833    Accepted Submission(s): 849 Problem Description M斐波那契数列F[n]是一种整数数列,

nare123的博客 351

M斐波那契数列 hdu 4549

M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 520    Accepted Submission(s): 146 Problem Description M斐波那契数列F[n]是一种整数数列,它的定

follow your dreams 781

hdu 4549 M斐波那契数列

f(n)表示斐波那契数列的第n项 F(n) = a^f(n-1)*b^f(n)  这个推一下就知道了 然后f(n)可以用矩阵快速幂求 1 1                         f(n+1)    f(n) 1 0  的n次幂   =   f(n)         f(n-1)   就行了(至于为什么有这个自己度娘把。。)  但关键点在于f(n)可能很大 a^f(n-

逝水流殇 592

hdu4549 M斐波那契数列

矩阵快速幂

zeal 171

HDU4549 M斐波那契数列

M斐波那契数列 题目分析: M斐波那契数列F[n]是一种整数数列,它的定义如下: F[0] = a F[1] = b F[n] = F[n-1] * F[n-2] ( n > 1 ) 现在给出a, b, n,你能求出F[n]的值吗? 算法分析:     经过前面几项的推导,你会发现其中a,b的个数为斐波那契数相同。而我们知道斐波那契数是到20项后就会很大

YouthDance 1199

HDU 4549 M斐波那契数列(矩阵幂)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4549 题意:F[0]=a,F[1]=b,F[n]=F[n-1]*F[n-2]。 思路:手算一下可以发现,最后F[n]=a^x*b^y,其中x和y是连续的两项Fib。因此只要求出这两个系数x和y即可。注意这里A^x=A^(x%Phi(C)+Phi(C)) (mod C)。因此在求矩阵快速幂时模的数不...

weixin_33785108的博客 127
上一篇: hdu 4545 ——魔法串
下一篇: hdu 4544 湫湫系列故事——消灭兔子
softrice
博客等级 码龄14年 24粉丝 195原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值