AT1980 [AGC001B] Mysterious Light 题解
简单递归题。
容易发现原题可以化为求边长分别为为
不难看出开始的两段由于等边三角形长度之和一定为大等边三角形边长,所以答案为
我们来看如何求
我们发现形式类似于辗转相除。当最后的
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#define int long long
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,x;
int solve(int x,int y){
if(y==0)
return -x;
int k=(x/y);
return k*2*y+solve(y,x%y);
}
signed main()
{
n=read(),x=read();
cout<<n+solve(x,n-x);
return 0;
}