当前位置:网站首页>HDU4565 So Easy! [matrix multiplication] [derivation]
HDU4565 So Easy! [matrix multiplication] [derivation]
2022-07-27 14:12:00 【51CTO】
Topic link :
http://acm.hdu.edu.cn/showproblem.php?pid=4565
The main idea of the topic :
Definition Sn = [( a + √b )^n] % m,[x] Express x Rounding up , such as [3.14] = 4. Here you are. a b n m Value ,
seek Sn How much is the .
Ideas :
This is a classic question , because (a-1)^2< b < a^2, therefore 0 < |a-√(b)| < 1, therefore
Sn = [( a + √b )^n] % m = ( [( a + √b )^n] + [( a - √b))^n] ) % m.
That is, the right is actually an integer , If you expand the binomial on the right , Except for the offsetting part , The rest is all
Integers . This formula sets An = (a + √b)^n,Bn = (a - √b)^n,Cn = [An],Sn = Cn % m.
First ask Cn The recurrence formula of .
set up Cn = pC(n-1) + qC(n-2), The characteristic equation is x^2 = p*x + q, from [( a + √b )^n] + [( a - √b))^n]
It can be seen that the characteristic roots are a + √b and a - √b. be p = 2*a,q = b - a^2.
be Cn = 2*a*C(n-1) + (b-a^2)C(n-2). Then start to construct the matrix
[ Cn ] = [ 2*a b-a^2 ] * [C(n-1)]
[C(n-1)] [ 1 0 ] [C(n-2)]
[ Cn ] = [ 2*a b-a^2 ] ^(n-2) * [C2]
[C(n-1)] [ 1 0 ] [C1]
From top Sn The formula shows ,C2 = 2*(a^2 + b),C1 = 2*a.
Then we use the fast power of matrix to get Cn, Then the output is OK .
AC Code :
边栏推荐
- [luogu_p5431] [template] multiplicative inverse 2 [number theory]
- Various ways to use new
- RSS tutorial: aggregate your own information collection channels, rshub, freshrss, NetNewsWire
- 基于C语言的LR1编译器设计
- Charles tutorial
- Chapter 3 business function development (add clues and remarks, and automatically refresh the added content)
- Unity2d -- camera follow
- 正掩码、反掩码、通配符
- Wechat campus laundry applet graduation design finished product (5) assignment
- printf函数缓冲区问题
猜你喜欢

Pure C handwriting thread pool
![[training day3] delete [simulation]](/img/7b/217d4a9fa1426107eb7d6890dc9dc5.png)
[training day3] delete [simulation]

Wechat campus laundry applet graduation design finished product (5) assignment

Design of LR1 compiler based on C language

【论文精读】Grounded Language-Image Pre-training(GLIP)

In the "meta cosmic space", utonmos will open the digital world of the combination of virtual and real
![[training day4] sequence transformation [thinking]](/img/2f/ab1ee75a871adfa9ad443c4a4886ae.png)
[training day4] sequence transformation [thinking]

NFT 的 10 种实际用途

C#测量工具示意图

井贤栋等蚂蚁集团高管不再担任阿里合伙人 确保独立决策
随机推荐
Deep confidence network (DBN) [the classical DBN network structure is a deep neural network composed of several layers of RBM (restricted Boltzmann machine) and one layer of BP]
<C> C语言哈希表使用
Cultural tourism and data collection | travel to Yunnan in an artistic way
Wechat campus laundry applet graduation design finished product of applet completion work (8) graduation design thesis template
Redis cluster setup - use docker to quickly build a test redis cluster
Some key information about Max animation (shift+v)
There is no need for semantic segmentation of annotation data! Eth & Leuven University proposed maskdistill, using transformer for unsupervised semantic segmentation, SOTA
NFT 的 10 种实际用途
Real image denoising based on multi-scale residual dense blocks and block connected cascaded u-net
[note] logistic regression
SLAM综述阅读笔记七:Visual and Visual-Inertial SLAM: State of the Art, Classification,and Experimental 2021
基于RoBERTa-wwm动态融合模型的中文电子病历命名实体识别
Vscode -- create template file
连接ResourceManager 失败
How to return to the parent directory with commands
SLAM综述阅读笔记六:基于图像语义的SLAM调研:移动机器人自主导航面向应用的解决方案 2020
基于预训练模型的多标签专利分类研究
A Keypoint-based Global Association Network for Lane Detection
YOLOX改进之一:添加CBAM、SE、ECA注意力机制
printf函数缓冲区问题