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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

2017 多校2 hdu 6053 TrickGCD

發布時間:2023/12/31 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2017 多校2 hdu 6053 TrickGCD 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2017 多校2 hdu 6053 TrickGCD

題目:

You are given an array \(A\) , and Zhu wants to know there are how many different array \(B\) satisfy the following conditions?

  • \(1≤B_i≤A_i\)
  • For each pair(\(l , r) (1≤l≤r≤n) , gcd(bl,bl+1...br)≥2\)

Input

The first line is an integer \(T(1≤T≤10)\) describe the number of test cases.

Each test case begins with an integer number n describe the size of array \(A\).

Then a line contains \(n\) numbers describe each element of \(A\)

You can assume that \(1≤n,A_i≤10^{5}\)

Output

For the \(k\)th test case , first output "Case #\(k\): " , then output an integer as answer in a single line . because the answer may be large , so you are only need to output answer mod \(10^{9}+7\)

思路:

枚舉\(g = gcd(b_1,b_2,....,b_n)\),
那么\(gcd為g\)的倍數的答案就是\(\prod_{i=1}^{n}\frac{A_i}{g}\)
每次暴力計算是不行的,想到一個數在\(g到2g-1\)除以g結果是不變的
所以可以預處理區間數字個數的前綴和,\(O(nlogn)\)類似素數篩法預處理出每個\(g\)的答案
現在要計算\(gcd為g\)的答案,我們從大到小枚舉,同時更新它的約數的答案,就可以保證不重復了
從小到大枚舉過去就要用到莫比烏斯函數去計算了
\(令F(i)為gcd為i的倍數的方案數,f(i)為gcd為i的方案數\)
\(F(i) = \sum_{i|d}^{}{f(d)} \rightarrow f(i) = \sum_{i|d}u(\fracozvdkddzhkzd{i})F(d)\)
代碼貼的是比賽時過的姿勢

#include<bits/stdc++.h> using namespace std; typedef pair<int,int> P; typedef long long LL; const int mod = 1e9 + 7; const int N = 1e5 + 10; vector<int> v[N]; int n; int sum[N],ans[N]; void init(){for(int i = 2;i < N;i++){for(int j = i;j < N;j+=i) v[j].push_back(i);} } int qpow(int x,int y){int ans = 1;while(y){if(y&1) ans = 1LL* ans * x % mod;x = 1LL * x * x % mod;y >>= 1;}return ans; } int main(void) {init();int T, x;int cas = 1;cin>>T;while(T--){memset(sum, 0, sizeof(sum));scanf("%d",&n);int mi = N;for(int i = 1;i <= n;i++) {scanf("%d",&x);mi = min(x,mi);sum[x]++;}for(int i = 1;i < N;i++) sum[i]+=sum[i-1];for(int i = 2;i <= mi;i++){ans[i] = 1;for(int j = i;j < N;j+=i){int l = j + i - 1 > N - 1?N-1:j + i - 1;ans[i] = 1LL * ans[i] * qpow(j / i,sum[l] - sum[j - 1]) % mod;}}int res = 0;for(int i = mi;i >= 2;i--){res = (res + ans[i])%mod;for(int j = 0;j < v[i].size();j++) ans[v[i][j]] = (ans[v[i][j]] - ans[i] + mod)%mod;}printf("Case #%d: %d\n",cas++,res);}return 0; }

轉載于:https://www.cnblogs.com/jiachinzhao/p/7267453.html

總結

以上是生活随笔為你收集整理的2017 多校2 hdu 6053 TrickGCD的全部內容,希望文章能夠幫你解決所遇到的問題。

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