博客
关于我
hdu6434 Problem I. Count(数论)(好题)
阅读量:395 次
发布时间:2019-03-05

本文共 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]);    }}

转载地址:http://sqewz.baihongyu.com/

你可能感兴趣的文章
nginx: [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:
查看>>
nginx:Error ./configure: error: the HTTP rewrite module requires the PCRE library
查看>>
Nginx:objs/Makefile:432: recipe for target ‘objs/src/core/ngx_murmurhash.o‘解决方法
查看>>
nginxWebUI runCmd RCE漏洞复现
查看>>
nginx_rtmp
查看>>
Nginx、HAProxy、LVS
查看>>
nginx一些重要配置说明
查看>>
Nginx下配置codeigniter框架方法
查看>>
Nginx与Tengine安装和使用以及配置健康节点检测
查看>>
Nginx中使用expires指令实现配置浏览器缓存
查看>>
Nginx中实现流量控制(限制给定时间内HTTP请求的数量)示例
查看>>
nginx中配置root和alias的区别
查看>>
nginx主要流程(未完成)
查看>>
Nginx之二:nginx.conf简单配置(参数详解)
查看>>
Nginx从入门到精通
查看>>
Nginx代理websocket配置(解决websocket异常断开连接tcp连接不断问题)
查看>>
Nginx代理初探
查看>>
nginx代理地图服务--离线部署地图服务(地图数据篇.4)
查看>>
Nginx代理外网映射
查看>>
Nginx代理模式下 log-format 获取客户端真实IP
查看>>