当前位置:网站首页>[atcoder1980] mystious light (mathematical simulation)
[atcoder1980] mystious light (mathematical simulation)
2022-06-11 07:36:00 【CaptainHarryChen】
The question
There is a side length of N(2<=N<=10^12) An equilateral triangle of mirrors , Set node as a,b,c, from ab Take a little bit of p, bring ap=X(1<=X<=N-1), from p A mysterious light is emitted horizontally to the right , After several reflections , go back to p spot . This mysterious light has one characteristic , He will leave a mirror on the path he has walked ( The light will be reflected by the path it has traveled ), Please come back finally p a.m. , The distance the light travels . 
Answer key
It is found that light always travels in a parallelogram , Parallelogram keeps shrinking , Pictured 

Let the short side of a parallelogram be a a , The long side is
The short side of the next parallelogram is b mod a b m o d a , The long side is a a , The journey of this transfer is
Until you come to the parallelogram whose side length is 0, Attention at the end , The last walk on the left is not 2a 2 a , yes a a <script type="math/tex" id="MathJax-Element-389">a</script>, It needs to be reduced once .
Code
#include<cstdio>
#include<algorithm>
using namespace std;
long long solve(long long a,long long b)
{
if(a==0)
return 0;
long long res=a*(b/a)*2;
if(b%a==0)
{
res-=a;
return res;
}
return res+solve(b%a,a);
}
int main()
{
long long N,X;
scanf("%lld%lld",&N,&X);
long long ans=N+solve(min(X,N-X),max(X,N-X));
printf("%lld\n",ans);
return 0;
}边栏推荐
- 2022 low voltage electrician test questions and online simulation test
- Seata的几种事务模式
- Simple configuration of vscade
- 【AtCoder1980】Mysterious Light(数学模拟)
- Use definite integral to calculate triangle area
- May 30-June 5, 2022 AI industry weekly (issue 100): three years
- Uoj 551 [unr 4] campus stroll [good polynomial questions (FOG)]
- QObject usage skills -- control function class
- C language judging big end and small end [consortium or pointer] big end and small end conversion
- 20200727 T2 small w playing game [generating function (binomial inversion technique)]
猜你喜欢

QT interface nested movement based on qscrollarea
![[STL source code analysis] summary notes (7): ingenious deque](/img/da/8ec42bfdbbf1b5bd1c2e396c2213e2.jpg)
[STL source code analysis] summary notes (7): ingenious deque

2、 User login and registration

【CodeForces1019E】Raining season(边分治+斜率优化)

Raspberry pie builds a full-featured NAS server (07): manage your library & read as you please

2022 low voltage electrician test questions and online simulation test

QT custom control library creation
![2020080 simulation competition [horizontal and vertical coordinates do not affect each other, cactus minimum cut, combined meaning translation formula]](/img/4d/a67a63d2c4eb80c98315c3057b01b9.jpg)
2020080 simulation competition [horizontal and vertical coordinates do not affect each other, cactus minimum cut, combined meaning translation formula]

2022年熔化焊接与热切割考试练习题及答案

Qstring to hexadecimal qstring
随机推荐
模线性方程组(中国剩余定理+通用解法)
零基础自学SQL课程 | OUTER JOIN外连接
After 4 years of naked resignation from the test, the test post of 15K interview was rubbed on the ground, and the result made me collapse and cry
Djikstra solves the shortest circuit with negative weight
自动化测试的生命周期是什么?
CRMEB/V4.4标准版打通版商城源码小程序公众号H5+App商城源码
A correction book full of sad tears
[analysis of STL source code] summary note (4): behind the scenes hero allocator
【HDU6357】Hills And Valleys(DP)
3年功能测试拿8K,被新来的反超,其实你在假装努力
C language volatile
[compilation principle] 05- syntax guided semantic computing -- Semantic Computing Based on translation mode
May 30-June 5, 2022 AI industry weekly (issue 100): three years
QT custom control library creation
[STL source code analysis] summary notes (12): functors and adapters
C memory alignment
学 SQL 必须了解的10个高级概念
Seata的几种事务模式
C language three chess games
Compound RateModel合約解析