博客
关于我
hdu6434 Problem I. Count(数论)(好题)
阅读量:382 次
发布时间: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/

你可能感兴趣的文章
Mybatis【3】-- Mybatis使用工具类读取配置文件以及从属性读取DB信息
查看>>
Mybatis【5】-- Mybatis多种增删改查那些你会了么?
查看>>
Mybatis【7】-- Mybatis如何知道增删改是否成功执行?
查看>>
计算输入的一句英文语句中单词数
查看>>
docker复制文件到宿主机
查看>>
lvs+keepalive构建高可用集群
查看>>
Mysql高可用架构(主从同步)
查看>>
mysql主从延迟高的原因
查看>>
ATS缓存数据结构
查看>>
glob模块
查看>>
6 个 Linux 运维典型问题
查看>>
Failed to get D-Bus connection: Operation not permitted解决
查看>>
oracle无法启动asm实例记录
查看>>
取消vim打开文件全是黄色方法
查看>>
一个系统部署多个tomcat实例
查看>>
HP服务器设置iLO
查看>>
从头实现一个WPF条形图
查看>>
.NET CORE(C#) WPF 方便的实现用户控件切换(祝大家新年快乐)
查看>>
C# WPF开源控件库:MahApps.Metro
查看>>
使用QT实现一个简单的登陆对话框(纯代码实现C++)
查看>>