当前位置:网站首页>[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;
}边栏推荐
- 【CodeForces1019E】Raining season(边分治+斜率优化)
- Compound RateModel合約解析
- 【IoT】项目管理:如何打造更好的跨职能团队?
- 【AtCoder2376】Black and White Tree(博弈)
- Find the longest common substring of N arrays (strings)
- Aiop introduction
- 远程办公经验 | 社区征文
- 测试4年裸辞失业,面试15k的测试岗被按在地上摩擦,结局让我崩溃大哭...
- JVM learning record (VII) -- class loading process and parental delegation model
- MFC custom string linked list
猜你喜欢

Decimal to binary

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

Miscellany C language

软件测试周刊(第75期):唯有平视,才能看见真实的自己。

2022 low voltage electrician test questions and online simulation test
![[IOT] project management: how to build a better cross functional team?](/img/df/28dbf0f7ba75d1bb3469cc15e70538.png)
[IOT] project management: how to build a better cross functional team?

二本毕业,银行外包测试工作 4 个月有余。聊聊一些真实感受 ...

Use definite integral to calculate triangle area

Zero foundation self-study SQL course | outer join external connection

10 advanced concepts that must be understood in learning SQL
随机推荐
Android and IOS reverse analysis / security detection / penetration testing framework
2022 low voltage electrician test questions and online simulation test
[Oracle database] mammy tutorial day02 use of database management tool sqlplus
Post-processing of ffmpeg miscellaneous notes
Software testing weekly (issue 75): only when you look down, can you see your true self.
How to prepare for the new PMP syllabus exam?
Several transaction modes of Seata
【Oracle 数据库】奶妈式教程day04 排序查询
nosqlzoo刷题-1
【AtCoder2387】+/- Rectangle
2、 User login and registration
20200727 T2 small w playing game [generating function (binomial inversion technique)]
【AtCoder2306】Rearranging(拓扑)
[software testing] 90% of the interviewers have been brushed out of such resumes
RTMP protocol
【NOIP2016 D1T3】换教室(期望DP+Floyd)(究极思维陷阱!)
自动化测试的生命周期是什么?
A case in which the MySQL administrator password cannot take effect
You got 8K in the 3-year function test, but you were actually pretending to work hard
QT table display data