跳到正文

剪贴板

剪贴板 2094ih5l

原文
剪贴板信息

剪贴板信息

收录
更新

自动计算器:200行。

A+B Problem 世纪难题(起源于帖子):

思路

设f1=A,f2=B,fn(n>2)=fn−1+fn−2,f_1=A,f_2=B,f_n(n>2)=f_{n-1}+f_{n-2},则f3f_3就是ANSWER A+BA+B。

推导

设qn=qn−1+qn−2,q^n=q^{n-1}+q^{n-2},解得(q≠0)q1=1+52,q2=1−52(q≠0)q_1=\frac{1+\sqrt{5}}{2},q_2=\frac{1-\sqrt{5}}{2}。
再设{fn=aq1n−1+bq2n−1f1=A,f2=B\begin{cases} f_n=aq_1^{n-1}+bq_2^{n-1} \\ f_1=A,f_2=B \end{cases}
代入,即得{a+b=Aa(1+52)+b(1−52)=B\begin{cases} a+b=A \\ a(\frac{1+\sqrt{5}}{2})+b(\frac{1-\sqrt{5}}{2})=B \end{cases}
解二元一次方程组得{a=B−A(1−52)5b=A(1+52)−B5\begin{cases} a=\frac{B-A(\frac{1-\sqrt{5}}{2})}{\sqrt{5}} \\ b=\frac{A(\frac{1+\sqrt{5}}{2})-B}{\sqrt{5}} \end{cases}
再代入得fn=15((B−A(1−52))(1+52)n−1+(A(1+52)−B)(1−52)n−1)f_n=\frac{1}{\sqrt{5}}((B-A(\frac{1-\sqrt{5}}{2}))(\frac{1+\sqrt{5}}{2})^{n-1}+(A(\frac{1+\sqrt{5}}{2})-B)(\frac{1-\sqrt{5}}{2})^{n-1})

解答

将n=3n=3代入fn=15((B−A(1−52))(1+52)n−1+(A(1+52)−B)(1−52)n−1)f_n=\frac{1}{\sqrt{5}}((B-A(\frac{1-\sqrt{5}}{2}))(\frac{1+\sqrt{5}}{2})^{n-1}+(A(\frac{1+\sqrt{5}}{2})-B)(\frac{1-\sqrt{5}}{2})^{n-1})
得 A+B=f3=15((B−A(1−52))(1+52)2+(A(1+52)−B)(1−52)2)=15((B−A(1−52))(3+52)+(A(1+52)−B)(3−52))\begin{aligned} A+B &= f_3\\ &= \frac{1}{\sqrt{5}}((B-A(\frac{1-\sqrt{5}}{2}))(\frac{1+\sqrt{5}}{2})^{2}+(A(\frac{1+\sqrt{5}}{2})-B)(\frac{1-\sqrt{5}}{2})^{2})\\ &= \frac{1}{\sqrt{5}}((B-A(\frac{1-\sqrt{5}}{2}))(\frac{3+\sqrt{5}}{2})+(A(\frac{1+\sqrt{5}}{2})-B)(\frac{3-\sqrt{5}}{2})) \end{aligned}

实现

只要计算15((B−A(1−52))(3+52)+(A(1+52)−B)(3−52))\frac{1}{\sqrt{5}}((B-A(\frac{1-\sqrt{5}}{2}))(\frac{3+\sqrt{5}}{2})+(A(\frac{1+\sqrt{5}}{2})-B)(\frac{3-\sqrt{5}}{2})),但怎么写?

C++
#include<bits/stdc++.h>
using namespace std;
int main()
{
	double a,b,c=sqrt(5);
	cin>>a>>b;
	printf("%.0lf",((b-a*(1.0-c)/2.0)*(3.0+c)/2.0+((a*(1.0+c)/2.0-b)*(3.0-c)/2.0))/c);
}
\boxed{\begin{gathered} \color{#000000}\rule{320pt}{450pt}\cr[-450pt] \begin{gathered}\colorbox{red}{\color{white}{\bf{MONKEY APPEARS}}}\end{gathered}\cr \color{white}{\text{我们正在提醒各位观猴的人们,也就是看到这份警告的您:}}\cr \begin{gathered}\color{white}{\bf{\text{道路千万条,规范第一条。}}}\end{gathered}\cr \begin{gathered}\color{white}{\bf{\text{观猴又对线,禁言两行泪。}}}\end{gathered}\cr \textcolor{#b0b0b0}{\underline{\kern{280pt}}}\cr \begin{gathered}\end{gathered} \begin{gathered}\color{white}{\text{为什么您会收到这条消息?这是因为:}}\end{gathered}\cr \begin{gathered}\color{white}{\bf{\underline{\text{某些猴子可能会发起挑衅,使您与它对线,从而达到哗众取宠的目的}}}}\end{gathered}\cr \begin{gathered}\color{white}{\text{我们建议,您在观猴的时候,注意以下几点:}}\end{gathered}\cr\kern{280pt}\cr[-10pt] \begin{aligned}&\kern{280pt}\cr[-10pt] &\bullet \color{yellow}\textbf{\text{不要和猴子疯狂对线——永远不要。}} \cr &\bullet \color{yellow}\textbf{\text{不要试图对其进行劝导或劝诫,它听不进去!}} \cr &\bullet \color{yellow}\textbf{\text{不要对猴子那可怜的IP进行DDoS攻击,请怜悯猴子们。}} \cr &\bullet \color{yellow}\textbf{\text{不要远程控制或关猴子的电脑——给猴子一些尊重罢。}} \cr &\bullet \color{yellow}\textbf{\text{不要不停地回复猴子——请让它尽情耍猴。}} \cr \end{aligned}\cr \begin{gathered}\color{white}{\text{同时,我们建议您做这些事情:}}\end{gathered}\cr \begin{aligned}&\kern{280pt}\cr[-10pt] &\bullet \color{yellow}\textbf{\text{静静地窥屏并等待管理员の出现。}} \cr &\bullet \color{yellow}\textbf{\text{多看看陶片。}} \cr &\bullet \color{yellow}\textbf{\text{举报猴子。}} \cr &\bullet \color{yellow}\textbf{\text{适当地和猴子对线。}} \cr &\bullet \color{yellow}\textbf{\text{奔走相告,让更多人前来观猴。}} \cr \end{aligned}\cr \begin{gathered}\color{white}{\text{最后,我们为这只可怜的猴子@meowjiao献上:}}\end{gathered}\cr \begin{gathered}\color{red}\Large\frak\fcolorbox{#40f0f0}{#faffe0}{Write my name in front of the \bf MOUNTAINS!}\end{gathered}\cr \textcolor{#b0b0b0}{\underline{\kern{280pt}}}\cr \begin{gathered}\color{white}{\small \text{如果你也想获得这份警告,请复制以下链接:}}\end{gathered}\cr \begin{gathered}\color{white}{\small https://www.luogu.com.cn/paste/tv7loauq} \end{gathered} \end{gathered}}

fabcdefghijklmnopqrstuvwxyz{f}_{a_{b_{c_{d_{e_{f_{g_{h_{i_{j_{k_{l_{m_{n_{o_{p_{q_{r_{s_{t_{u_{v_{w_{x_{y_{z}}}}}}}}}}}}}}}}}}}}}}}}}} 我的主页里怎么还能藏这种东西捏? 火车头:

C++
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<fstream>
#include<sstream>
#include<iomanip>
#include<cassert>
#include<queue>
#include<stack>
#include<bitset>
#include<random>
#include<chrono>
#include<limits>
#include<functional>
#include<numeric>
#include<unordered_map>
#include<unordered_set>
#include<stdexcept>
#include<type_traits>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<iterator>
#include<thread>
#include<mutex>
#include<condition_variable>
#include<atomic>
#include<regex>
#include<locale>
#include<tuple>
#include<array>
#include<initializer_list>
#include<forward_list>
#include<deque>
#include<list>
#include<queue>
#include<stack>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
#include<setjmp.h>
#include<signal.h>
#include<pthread.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<unistd.h>
#include<getopt.h>
#include<errno.h>
#include<sys/file.h>
#include<malloc.h>
#include<memory.h>
#include<signal.h>
#include<setjmp.h>
#include<time.h>
#include<math.h>
#include<ctype.h>
#include<float.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<assert.h>
#include<stddef.h>
#include<errno.h>
#include<inttypes.h>
#include<limits.h>
#include<locale.h>
#include<stdarg.h>
#include<stdint.h>
#include<stdarg.h>
#include<time.h>
#include<unistd.h>
#include<conio.h>

第一场 codeforces 打了 546546 分:HOTNEWS! pASEzyd.png Exgcd模板:

C++
void Exgcd(long long a,long long b,long long &x,long long &y)
{
	if(!b) x=1,y=0;
	else Exgcd(b,a%b,y,x) y-=a/b*x;
}