题意:给一个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) (欧拉函数打表)的更多相关文章

  1. 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 ...

  2. UVA 11426 GCD - Extreme (II) (欧拉函数+筛法)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/O 题意是给你n,求所有gcd(i , j)的和,其中 ...

  3. 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< ...

  4. UVA 11426 GCD - Extreme (II) 欧拉函数

    分析:枚举每个数的贡献,欧拉函数筛法 #include <cstdio> #include <iostream> #include <ctime> #include ...

  5. 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) 此 ...

  6. UVA11426 GCD - Extreme (II) (欧拉函数/莫比乌斯反演)

    UVA11426 GCD - Extreme (II) 题目描述 PDF 输入输出格式 输入格式: 输出格式: 输入输出样例 输入样例#1: 10 100 200000 0 输出样例#1: 67 13 ...

  7. UVA11426 GCD - Extreme (II)---欧拉函数的运用

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. UVA11426 GCD - Extreme (II) —— 欧拉函数

    题目链接:https://vjudge.net/problem/UVA-11426 题意: 求 ∑ gcd(i,j),其中 1<=i<j<=n . 题解:1. 欧拉函数的定义:满足 ...

  9. UVA 11426 - GCD - Extreme (II) (数论)

    UVA 11426 - GCD - Extreme (II) 题目链接 题意:给定N.求∑i<=ni=1∑j<nj=1gcd(i,j)的值. 思路:lrj白书上的例题,设f(n) = gc ...

随机推荐

  1. IE下使用location对象有时会出现“没有权限”的错误

    http://jadyyang.blog.sohu.com/145340845.html ——————————————————————————————————————————————————————— ...

  2. OracleHelper.cs

    using System;using System.Collections.Generic;using System.Linq;using System.Text; using System.Conf ...

  3. 嵌入式开发之信号采集同步---VSYNC和HSYNC的作用以及它们两者之间的关系

    VSYNC和HSYNC的作用以及它们两者之间的关系 VSYNC和HSYNC的作用以及它们两者之间的关系 VSYNC和HSYNC是什么 VSYNC: vertical synchronization,指 ...

  4. hadoop入门学习整理

    技术性网站 1.http://dongxicheng.org/ 2.http://www.iteblog.com/ 3.http://www.cnblogs.com/shishanyuan/p/414 ...

  5. nginx tomcat https配置方案

    nginx目录下配置: ssl目录下 添加 证书和密码,如图 /etc/nginx/conf.d  下修改配置文件 HTTP域名的配置: ## Basic reverse proxy server # ...

  6. No transactional EntityManager available; nested exception is javax.persistence.TransactionRequiredException: No transactional EntityManager available

    参考地址:http://docs.spring.io/spring-data/jpa/docs/current/api/org/springframework/data/jpa/repository/ ...

  7. Windows窗口的层次关系(转)

    今天看到这篇文章,觉得蛮有用的,我之前也对这个不大了解,特转载此处. 转载地址:http://www.51testing.com/html/200804/n80848.html 在Window 的图形 ...

  8. 160628、利用Oracle rownum让表排序字段值连续

    利用Oracle rownum让表排序字段值连续 1.需求说明 表(eval_index)中有字段如下: 表字段 描述 说明 ID 主键 GROUP_ID 分组编号 SORT_NUM 排序序号 按照分 ...

  9. k8s更新Pod镜像

    实际使用k8s中,如果使用RC启动pod可以直接使用滚动更新进行pod版本的升级,但是我们使用的情况是在pod里面启动有状态的mysql服务,没有和RC进行关联,这样更新的时候只能通过 更新pod的配 ...

  10. ubuntu/debian gpg error no_pubkey 解决方法

    GPG error: http://ppa.launchpad.net precise Release: The following signatures couldn’t be verified b ...