UESTC - 1724 GCD区间求和
依然是神奇的欧拉函数
若GCD(n,i)=k
则GCD(n/k,i/k)=1,
令i/k=x,有GCD(n/k,x)=1,
→k*GCD(n/k,x)=1中x的个数 = GCD(n,i)=k的和
范围就是求n的所有因子k
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+11;
typedef unsigned long long ll;
ll phi[maxn];
void euler(int n){
for(int i = 1; i <= n; i++){
phi[i]=i;
}
for(int i = 2; i <= n; i++){
if(phi[i]==i){
for(int j = i; j <= n; j+=i){
phi[j]=phi[j]/i*(i-1);
}
}
}
}
vector<int> P;
void chai(int n){
P.clear();
for(ll i = 1; i*i <= n; i++){
if(n%i==0){
P.push_back(i);
if(n/i!=i) P.push_back(n/i);
}
}
}
int a[maxn],n;
int main(){
euler(maxn-1);
while(scanf("%d",&n)!=EOF){
ll ans=0;
for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
for(int i = 1; i <= n; i++){
chai(a[i]);
for(int j = 0; j < P.size(); j++){
ans+=phi[a[i]/P[j]]*P[j];
}
ans-=a[i];
}
printf("%llu\n",ans);
}
return 0;
}
UESTC - 1724 GCD区间求和的更多相关文章
- POJ 2823 Sliding Window 线段树区间求和问题
题目链接 线段树区间求和问题,维护一个最大值一个最小值即可,线段树要用C++交才能过. 注意这道题不是求三个数的最大值最小值,是求k个的. 本题数据量较大,不能用N建树,用n建树. 还有一种做法是单调 ...
- POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)
A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...
- vijos1740 聪明的质监员 (二分、区间求和)
http://www.rqnoj.cn/problem/657 https://www.vijos.org/p/1740 P1740聪明的质检员 请登录后递交 标签:NOIP提高组2011[显示标签] ...
- LightOJ 1112 Curious Robin Hood (单点更新+区间求和)
http://lightoj.com/volume_showproblem.php?problem=1112 题目大意: 1 i 将第i个数值输出,并将第i个值清0 2 i v ...
- 洛谷 P1890 gcd区间
P1890 gcd区间 题目提供者 洛谷OnlineJudge 标签 数论(数学相关) 难度 普及/提高- 题目描述 给定一行n个正整数a[1]..a[n]. m次询问,每次询问给定一个区间[L,R] ...
- POJ 3468 A Simple Problem with Integers(线段树区间求和)
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...
- poj3468 A Simple Problem with Integers(线段树模板 功能:区间增减,区间求和)
转载请注明出处:http://blog.csdn.net/u012860063 Description You have N integers, A1, A2, ... , AN. You need ...
- poj3468树状数组的区间更新,区间求和
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 47174 ...
- D 区间求和 [数学 树状数组]
D 区间求和 题意:求 \[ \sum_{k=1}^n \sum_{l=1}^{n-k+1} \sum_{r=l+k-1}^n 区间前k大值和 \] 比赛时因为被B卡了没有深入想这道题 结果B没做出来 ...
随机推荐
- 一个虚拟机网络的XML描述
<?xml version="1.0" encoding="utf-8"?> <VNET> <ID>1</ID> ...
- ROS源码解读(二)--全局路径规划
博客转载自:https://blog.csdn.net/xmy306538517/article/details/79032324 ROS中,机器人全局路径规划默认使用的是navfn包 ,move_b ...
- Python基础入门-While循环
讲完了for循环我们继续来看第二个循环,那就是while循环,while循环和for循环虽然都是循环,但是有着本质的不同.我们先来看下她们之间的区别和联系: While循环和for循环区别: 1.fo ...
- web大文件上传控件-监控fd_create流程-Xproer.HttpUploader6
监控fd_create流程 1.打开ie,f12 2.启动网络监控 点击开始捕获 上传文件夹,然后查看监控 将监控信息转到详细视图
- py_initialize:C调Python出错 是初始化错误?
还是pythonpath和pythonname变量没有配置正确? py_initialize()方法是什么? In an application embedding Python, this shou ...
- 编写高质量代码改善C#程序的157个建议——建议2: 使用默认转型方法
建议2: 使用默认转型方法 除了字符串操作外,程序员普遍会遇到的第二个问题是:如何正确地对类型实现转型.在上一个建议中,从int转型为string,我们使用了类型int的ToString方法.在大部分 ...
- 20169219 实验三 敏捷开发与XP实践 报告
实验内容 1.求命令行传入整数参数的和. package exp3; public class TestArgs01 { public static void main(String[] args) ...
- 让Fireball CodeEditor控件禁止中文双倍输入
第一次使用这个控件的时候,输入注释时候, 中文都是双倍输入,很是郁闷,查到资料,在 让Fireball CodeEditor控件支持中文 这篇文章中使用的方法,将代码复制过来发现不适用, 后来再一次偶 ...
- IdentityServer4实现单点登录统一认证
什么是单点登录统一认证:假如某公司旗下有10个网站(比如各种管理网站:人事系统啊,财务系统啊,业绩系统啊等),我是该公司一管理员或者用户,按照传统网站模式是这样:我打开A网站 输入账号密码 然后进入到 ...
- golang subprocess tests
golang Subprocess tests Sometimes you need to test the behavior of a process, not just a function. f ...