
hdu6434 Problem I. Count(数论)(好题)
发布日期:2021-05-08 15:18:34
浏览次数:13
分类:原创文章
本文共 1325 字,大约阅读时间需要 4 分钟。
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
思路:
变换差不多就是这样,于是对于每一个i就变成了求2i的欧拉函数除2了,求一下前缀和就行。
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int N=2e7+5;ll euler[N<<1],sum[N],prim[N<<1];void get_euler(int n){ //欧拉函数 memset(euler, 0, sizeof euler); euler[1] = 1; int id = 0; for(int i = 2; i < n; ++i) { if(!euler[i]) { euler[i] = i - 1; prim[id++] = i; } for(int j = 0; j < id && prim[j]*i <n; ++j) { if(i % prim[j]) { euler[i*prim[j]] = euler[i] * (prim[j]-1); } else { euler[i*prim[j]] = euler[i] * prim[j]; break; } } }}int main(){ int n,T; get_euler(N<<1); sum[1]=0; for(int i=2;i<=N;++i) sum[i]=euler[2*i]/2,sum[i]+=sum[i-1]; scanf("%d",&T); while(T--) { scanf("%d",&n); printf("%lld\n",sum[n]); }}
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年03月23日 21时50分04秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
koa2 中间件里面的next到底是什么
2021-05-09
在create-react-app创建的项目下允许函数绑定运算符
2021-05-09
博客园新闻频道开始公开测试
2021-05-09
评论表聚集索引引起的评论超时问题
2021-05-09
博客园上海俱乐部4月份活动通知邀请函已经发出!
2021-05-09
上周热点回顾(5.24-5.30)
2021-05-09
Internet Explorer 10 专题上线
2021-05-09
云计算之路-阿里云上:0:25~0:40网络存储故障造成网站不能正常访问
2021-05-09
网站故障公告1:使用阿里云RDS之后一个让人欲哭无泪的下午
2021-05-09
上周热点回顾(12.31-1.6)
2021-05-09
上周热点回顾(1.21-1.27)
2021-05-09
上周热点回顾(6.3-6.9)
2021-05-09
上周热点回顾(8.12-8.18)
2021-05-09
【故障公告】升级阿里云 RDS SQL Server 实例故障经过
2021-05-09
蹒跚来迟:新版博客后台上线公测
2021-05-09
上周热点回顾(9.16-9.22)
2021-05-09
上周热点回顾(11.4-11.10)
2021-05-09
[网站公告]11月26日00:00-04:00阿里云RDS升级
2021-05-09
[网站公告]又拍云API故障造成图片无法上传(已恢复)
2021-05-09
上周热点回顾(12.16-12.22)
2021-05-09