日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

agc015F - Kenus the Ancient Greek(结论题)

發布時間:2023/12/20 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 agc015F - Kenus the Ancient Greek(结论题) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意

題目鏈接

$Q$組詢問,每次給出$[x, y]$,定義$f(x, y)$為計算$(x, y)$的最大公約數需要的步數,設$i \leqslant x, j \leqslant y$,求$max(f(i, j))$,以及$max(f(i, j))$不同的數對$(i, j)$的個數

Sol

結論題Orz

設$f(x, y)$表示$(x, y)$輾轉相除需要的步數,$fib(i)$表示第$i$個斐波那契數

常識:$f(fib[i], fib[i+1]) = i$。

定義一個數對是“好的”,當且僅當對于$(x, y)$,不存在更小的$x', y'$使得$f(x', y') > f(x, y)$

顯然我們需要統計的數對一定是好的數對

定義一個數對是“優秀的”,當且僅當對于$(x, y)$,若$f(x, y) = k$, 滿足$x, y \leqslant fib[k+2] + fib[k-1]$

結論!:一個好的數對輾轉相除一次后一定是優秀的數對!

證明可以用反證法,也就是我先假設一個$f(a, b) = i$是好的,但是得到的數對$(x, y)$滿足$y > fib[k+2] + fib[k-1]$

但是這樣我們會得到一個$x' = f[i+2], y' = f[i+2]$滿足$f(x', y')>f(a, b)$,所以不成立

那么現在要做的就是求“優秀的”數對的個數。

考慮直接用歐幾里得算法的定義遞推即可

不過代碼是真·難寫啊,去網上copy一份吧。。。

#include<iostream> #include<cstdio> #include<algorithm> #include<vector> #define Pair pair<LL, LL> #define MP(x, y) make_pair(x, y) #define fi first #define se second #define LL long long #define int long long using namespace std; const int MAXN = 1e6 + 10, B = 90, mod = 1e9 + 7; inline LL read() {char c = getchar(); LL x = 0, f = 1;while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();return x * f; } vector<Pair> v[B + 1]; LL f[B + 1]; void Pre() {f[0] = f[1] = 1;for(int i = 2; i <= B; i++) f[i] = f[i - 1] + f[i - 2];v[1].push_back(MP(1, 2)); v[1].push_back(MP(1, 3)); v[1].push_back(MP(1, 4));for(int i = 1; i <= B - 3; i++) {for(int j = 0; j < v[i].size(); j++) {LL x = v[i][j].fi, y = v[i][j].se;LL tmp = x; x = y; y = tmp + y;while(y <= f[i + 3] + f[i - 1]) v[i + 1].push_back(MP(x, y)), y += x;}} } main() {// freopen("1.in", "r", stdin); Pre();int Q = read();while(Q--) {LL x = read(), y = read(), K;if(x > y) swap(x, y);for(K = 1; f[K + 1] <= x && f[K + 2] <= y; K++);cout << K << " ";if(K == 1) {cout << x * y % mod << endl; continue;}LL ans = 0;for(int i = 0; i < v[K - 1].size(); i++) {LL a = v[K - 1][i].fi, b = v[K - 1][i].se;// printf("%I64d %I64d\n", a, b);if(b <= x) ans += (y - a) / b % mod;if(b <= y) ans += (x - a) / b % mod;//if(a + b <= x && b <= y) ans++;//if(a + b <= y && a <= x) ans++;ans %= mod;}cout << ans % mod<< endl;}return 0; }

?

轉載于:https://www.cnblogs.com/zwfymqz/p/9677497.html

總結

以上是生活随笔為你收集整理的agc015F - Kenus the Ancient Greek(结论题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。