uva 11426 GCD - Extreme (II) (欧拉函数打表)
题意:给一个N,和公式
求G(N)。
分析:设F(N)= gcd(1,N)+gcd(2,N)+...gcd(N-1,N)。则 G(N ) = G(N-1) + F(N)。
设满足gcd(x,N) 值为 i 的且1<=x<=N-1的x的个数为 g(i,N)。 则F(N) = sigma{ i * g(i,N) }。
因为gcd(x,N) == i 等价于 gcd(x/i, N/i) == 1,且满足gcd(x/i , N/i)==1的x的个数就是 N/i 的欧拉函数值。所以g(i,N) 的值 就是phi(N/i)。
打表预处理出每个数的欧拉函数值和每个数对应的答案即可。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 4e6+;
int phi[maxn]; //欧拉函数
LL ans[maxn];
void Euler()
{ //欧拉函数表
for(int i=;i<maxn;++i) phi[i] = i;
for(int i=;i<maxn;++i){
if(phi[i]!=i) continue;
for(int j=i;j<maxn;j+=i)
phi[j] = phi[j] - phi[j]/ i;
}
for(int i=;i<maxn;++i){
for(int j=i+i;j<maxn;j+=i){
ans[j] += i*phi[j/i];
}
}
for(int i=;i<maxn;++i) ans[i]+=ans[i-];
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
Euler();
int N;
while(scanf("%d",&N)==){
if(!N) break;
printf("%lld\n",ans[N]);
}
return ;
}
uva 11426 GCD - Extreme (II) (欧拉函数打表)的更多相关文章
- UVA 11426 GCD - Extreme (II)(欧拉函数打表 + 规律)
Given the value of N, you will have to find the value of G. The definition of G is given below:Here ...
- UVA 11426 GCD - Extreme (II) (欧拉函数+筛法)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/O 题意是给你n,求所有gcd(i , j)的和,其中 ...
- UVA 11426 - GCD - Extreme (II) 欧拉函数-数学
Given the value of N, you will have to find the value of G. The definition of G is given below:G =i< ...
- UVA 11426 GCD - Extreme (II) 欧拉函数
分析:枚举每个数的贡献,欧拉函数筛法 #include <cstdio> #include <iostream> #include <ctime> #include ...
- UVA 11424 GCD - Extreme (I) (欧拉函数+筛法)
题目:给出n,求gcd(1,2)+gcd(1,3)+gcd(2,3)+gcd(1,4)+gcd(2,4)+gcd(3,4)+...+gcd(1,n)+gcd(2,n)+...+gcd(n-1,n) 此 ...
- UVA11426 GCD - Extreme (II) (欧拉函数/莫比乌斯反演)
UVA11426 GCD - Extreme (II) 题目描述 PDF 输入输出格式 输入格式: 输出格式: 输入输出样例 输入样例#1: 10 100 200000 0 输出样例#1: 67 13 ...
- UVA11426 GCD - Extreme (II)---欧拉函数的运用
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA11426 GCD - Extreme (II) —— 欧拉函数
题目链接:https://vjudge.net/problem/UVA-11426 题意: 求 ∑ gcd(i,j),其中 1<=i<j<=n . 题解:1. 欧拉函数的定义:满足 ...
- UVA 11426 - GCD - Extreme (II) (数论)
UVA 11426 - GCD - Extreme (II) 题目链接 题意:给定N.求∑i<=ni=1∑j<nj=1gcd(i,j)的值. 思路:lrj白书上的例题,设f(n) = gc ...
随机推荐
- java项目的部署
1.将tomocat解压到服务器上 2.放项目war包. 3.war包解压. 4.修改端口配置. 1.<Server port="8024" shutdown="S ...
- Tomcat服务器的默认端口是多少?怎样修改tomcat的端口?
Tomcat服务器的默认端口是多少?怎样修改tomcat的端口? 解答:默认端口为8080,可以通过service.xml的Connector元素的port属性来修改端口.
- HibernateSessionFactory演示样例
package common; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hi ...
- python3的安装,Window与linux
一.window安装 1.首先是window下的安装. 进入python网站https://www.python.org/downloads/下载页面,选择所需要的版本进行下载. 点击Download ...
- 为什么要使用docker
1. 为什么要使用Docker Docker容器虚拟化的好处 Docker项目的发起人和Docker Inc.的CTO Solomon Hykes认为,Docker在正确的地点.正确的时间顺应了正确的 ...
- servlet ; basepath ; sendredirected ;
Eclipse 新建 jsp页面里自动生成以下代码: <%String path = request.getContextPath();String basePath = request.get ...
- 160808、Java的不同版本:J2SE、J2EE、J2ME的区别
来源:微学苑 在Java中,同一个类中的多个方法可以有相同的名字,只要它们的参数列表不同就可以,这被称为方法重载(method overloading). 参数列表又叫参数签名,包括参数的类型.参数的 ...
- Java 8 Lambda 表达式详解
一.Java 8 Lambda 表达式了解 参考:Java 8 Lambda 表达式 | 菜鸟教程 1.1 介绍: Lambda 表达式,也可称为闭包,是推动 Java 8 发布的最重要新特性. La ...
- DPM Server切换
DPMserver切换: Dpm有2个volum:副本卷和恢复点卷 (1)首先在exchangeserver上面安装agent (2)在exchangeserver上指定dpmserver: cd&q ...
- TGI指数
TGI指数 目标人群中国具有某一特征的群体占比/总体中具有相同特征的群体的占比*标准数100