AtCoder Grand Contest 001
题意:从一个正三角形边上一点出发,遇到边和已走过的边则反弹,问最终路径长度
思路:GCD
数据爆long long
1 #pragma comment(linker, "/STACK:102c000000,102c000000") 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <sstream> 6 #include <string> 7 #include <algorithm> 8 #include <list> 9 #include <map> 10 #include <vector> 11 #include <queue> 12 #include <stack> 13 #include <cmath> 14 #include <cstdlib> 15 // #include <conio.h> 16 using namespace std; 17 #define clc(a,b) memset(a,b,sizeof(a)) 18 #define inf 0x3f3f3f3f 19 #define lson l,mid,rt<<1 20 #define rson mid+1,r,rt<<1|1 21 const int N = 3*1e6+10; 22 const int MOD = 1e9+7; 23 #define LL long long 24 #define mi() (l+r)>>1 25 double const pi = acos(-1); 26 27 void fre() { 28 freopen("in.txt","r",stdin); 29 } 30 31 // inline int r() { 32 // int x=0,f=1;char ch=getchar(); 33 // while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();} 34 // while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f; 35 // } 36 37 LL Gcd(LL a,LL b){ return b? Gcd(b, a % b) : a; } 38 int main(){ 39 LL n,x; cin >> n >> x; 40 LL d = Gcd(n,x); 41 n/=d; 42 unsigned long long ans=d*3*(n-1); 43 printf("%llu\n",ans); 44 }