A+B Problem 世纪难题(起源于帖子):
思路
设f1=A,f2=B,fn(n>2)=fn−1+fn−2,则f3就是ANSWER A+B。
推导
设qn=qn−1+qn−2,解得(q=0)q1=21+5,q2=21−5。
再设{fn=aq1n−1+bq2n−1f1=A,f2=B
代入,即得{a+b=Aa(21+5)+b(21−5)=B
解二元一次方程组得⎩⎨⎧a=5B−A(21−5)b=5A(21+5)−B
再代入得fn=51((B−A(21−5))(21+5)n−1+(A(21+5)−B)(21−5)n−1)
解答
将n=3代入fn=51((B−A(21−5))(21+5)n−1+(A(21+5)−B)(21−5)n−1)
得
A+B=f3=51((B−A(21−5))(21+5)2+(A(21+5)−B)(21−5)2)=51((B−A(21−5))(23+5)+(A(21+5)−B)(23−5))
实现
只要计算51((B−A(21−5))(23+5)+(A(21+5)−B)(23−5)),但怎么写?
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
我的主页里怎么还能藏这种东西捏?
火车头:
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 打了 546 分:HOTNEWS!
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;
}