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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

杭电多校第十场 hdu6434 Count 欧拉函数打表 快速打表模板

發布時間:2024/4/17 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 杭电多校第十场 hdu6434 Count 欧拉函数打表 快速打表模板 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Problem I. Count

Time Limit: 4000/2000 MS (Java/Others)????Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 42????Accepted Submission(s): 16


Problem Description Multiple query, for each n, you need to get
n i-1
∑ ∑ [gcd(i + j, i - j) = 1]
i=1 j=1

?

Input On the first line, there is a positive integer T, which describe the number of queries. Next there are T lines, each line give a positive integer n, as mentioned above.
T<=1e5, n<=2e7

?

Output Your output should include T lines, for each line, output the answer for the corre- sponding n.

?

Sample Input 4 978 438 233 666

?

Sample Output 194041 38951 11065 89963

?

Source 2018 Multi-University Training Contest 10

?

Recommend chendu???|???We have carefully selected several similar problems for you:??6437?6436?6435?6434?6433? 題意:求下面這個式子的值 n i-1
∑ ∑ [gcd(i + j, i - j) = 1]
i=1 j=1 分析:按照上面那個式子直接暴力打表容易得到上面式子的含義是1-n以內偶數的歐拉函數值加上奇數的歐拉函數值除以2的和(注意要快速打表,運用素數快速打表) AC代碼: #include <map> #include <set> #include <stack> #include <cmath> #include <queue> #include <cstdio> #include <vector> #include <string> #include <bitset> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #define ls (r<<1) #define rs (r<<1|1) #define debug(a) cout << #a << " " << a << endl using namespace std; typedef long long ll; const ll maxn = 2*1e7+10; const ll mod = 998244353; const double pi = acos(-1.0); const double eps = 1e-8; ll num[maxn], sum[maxn], prim[maxn]; int main() {ios::sync_with_stdio(0);ll T, n;memset(num, 0, sizeof num);num[1] = 1;ll id = 0;for( ll i = 2; i <= maxn-10; i ++ ) {if(!num[i]) {num[i] = i - 1; prim[id++] = i;}for( ll j = 0; j < id && prim[j]*i <= maxn-10; j ++ ) {if(i % prim[j]) {num[i*prim[j]] = num[i] * (prim[j]-1);}else {num[i*prim[j]] = num[i] * prim[j];break;}}}num[1] = 0;sum[1] = 0;for( ll i = 2; i <= maxn-10; i ++ ) {if( i%2 == 0 ) {sum[i] = sum[i-1] + num[i];} else {sum[i] = sum[i-1] + num[i]/2;}}scanf("%lld",&T);while( T -- ) {scanf("%lld",&n);printf("%lld\n",sum[n]);}return 0; }

  

轉載于:https://www.cnblogs.com/l609929321/p/9519403.html

總結

以上是生活随笔為你收集整理的杭电多校第十场 hdu6434 Count 欧拉函数打表 快速打表模板的全部內容,希望文章能夠幫你解決所遇到的問題。

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