当前位置:网站首页>[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;
}边栏推荐
- Regular Expression Matching
- Smart pointer (simple version)
- Paging of the flask page
- 【集群】haproxy负载均衡
- 【HDU6357】Hills And Valleys(DP)
- 2020080 simulation competition [horizontal and vertical coordinates do not affect each other, cactus minimum cut, combined meaning translation formula]
- May 30-June 5, 2022 AI industry weekly (issue 100): three years
- 【NOIP2016 D1T3】换教室(期望DP+Floyd)(究极思维陷阱!)
- Directrix of ellipse
- 测试4年裸辞失业,面试15k的测试岗被按在地上摩擦,结局让我崩溃大哭...
猜你喜欢

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

2022 low voltage electrician operation certificate test question simulation test platform operation

Simple configuration of vscade

【Oracle 数据库】奶妈式教程day04 排序查询

JVM tuning
![[STL source code analysis] summary notes (7): ingenious deque](/img/da/8ec42bfdbbf1b5bd1c2e396c2213e2.jpg)
[STL source code analysis] summary notes (7): ingenious deque

【编译原理】05-语法制导的语义计算——基于翻译模式的语义计算

Several transaction modes of Seata
![[Oracle database] mammy tutorial day03 Sorting Query](/img/ea/24c9495a2ef4f1786f7b7852bde321.png)
[Oracle database] mammy tutorial day03 Sorting Query

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
随机推荐
Software testing weekly (issue 75): only when you look down, can you see your true self.
Analyse du contrat du modèle de taux composé
【软件测试】这样的简历已经刷掉了90%的面试者
20200803 T3 my friends [divide and conquer NTT optimization recursion]
Flask页面的分页
[compilation principle] 05- syntax guided semantic computing -- Semantic Computing Based on translation mode
CRMEB/V4.4标准版打通版商城源码小程序公众号H5+App商城源码
[IOT] project management: how to build a better cross functional team?
2. Graduated from this course, and the bank has outsourced testing work for more than 4 months. Talk about some real feelings
Configuration software -- control import
MFC custom string linked list
Wc2020 course selection
黑群晖DSM7.0.1物理机安装教程
Raspberry pie builds a full-featured NAS server (07): manage your library & read as you please
零基础自学SQL课程 | UNION 联合查询
Uoj 554 [unr 4] challenges Hamilton [find Hamilton path (adjustment method)]
JVM tuning
2022低压电工考题及在线模拟考试
JVM learning record (VII) -- class loading process and parental delegation model
C language to write a calculator calculation logic