思路:
对于两个点,从fib数列的后面开始减,一直减的相等
//std 80, 一堆bug #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #include <string> using namespace std; const int N = 95; #define LL long long LL f[N]; LL m; inline LL read() { LL x = 0; char c = getchar(); while(c < '0' || c > '9') c = getchar(); while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x; } int main() { freopen("fibonacci.in", "r", stdin); freopen("fibonacci.out", "w", stdout); f[1] = 1; f[2] = 1; for(int i = 3; i <= 90; i ++) f[i] = f[i - 1] + f[i - 2]; m = read(); for(int i = 1; i <= m; i ++) { LL a = read(); LL b = read(); if(a < b) swap(a, b);//baozheng a > b; bool flag = 1; int js = 90; while(a != b) { if(a > f[js]) a -= f[js]; if(b > f[js]) b -= f[js]; js --; } printf("%I64d ", a); } return 0; } /* 5 1 1 2 3 5 7 7 13 4 12 */