题目链接:https://vjudge.net/problem/UVA-11426

题意:

求 ∑ gcd(i,j),其中 1<=i<j<=n 。

题解:
1. 欧拉函数的定义:满足 0<x<n 且 gcd(x,n) = 1 的x有euler[n]个。

2. 可以推论出:满足 0<2*x<2*n 且 gcd(2*x,2*n) = 2 的2*x同样有euler[n]个,推向一般:满足 0<k*x<k*n 且 gcd(k*x,k*n) = k 的k*x有euler[n]个。解释:其实就是对于n来说,在1~n-1内与它互质的数都乘上相应的倍数,同时n也乘上相应的倍数,因而他们的最大公约数也为乘上的倍数,但不管如何,个数没有改变,仍为euler[n]个,只不过是他们的值“放大”了罢。

3. 有了上述结论,就可以枚举每个欧拉函数euler[n]和系数k,然后进行统计。

AC代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = +; int euler[MAXN];
void getEuler()
{
memset(euler, , sizeof(euler));
euler[] = ;
for(int i = ; i<MAXN; i++) if(!euler[i]) {
for(int j = i; j<MAXN; j += i)
{
if(!euler[j]) euler[j] = j;
euler[j] = euler[j]/i*(i-);
}
}
} LL sum[MAXN];
void init()
{
getEuler();
memset(sum, , sizeof(sum));
for(int i = ; i<MAXN; i++) // 枚举“单位”欧拉数
for(int k = ; i*k<MAXN; k++) // 枚举倍数
sum[i*k] += k*euler[i]; for(int i = ; i<MAXN; i++)
sum[i] += sum[i-];
} int main()
{
init();
int n;
while(scanf("%d", &n) &&n)
printf("%lld\n", sum[n]);
}

UVA11426 GCD - Extreme (II) —— 欧拉函数的更多相关文章

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

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

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

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

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

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

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

  5. 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) 值为 ...

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

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

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

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

  9. GCD - Extreme(欧拉函数变形)

    题目链接:https://vjudge.net/problem/UVA-11426 题目大意: 给出整数n∈[2,4000000],求解∑gcd(i,j),其中(i,j)满足1≤i<j≤n. 的 ...

随机推荐

  1. 2017.2.16 开涛shiro教程-第十七章-OAuth2集成(一)服务器端

    原博客地址:http://jinnianshilongnian.iteye.com/blog/2018398 根据下载的pdf学习. 开涛shiro教程-第十七章-OAuth2集成 1.OAuth2介 ...

  2. from: Maven实战(九)——打包的技巧

    from : http://www.infoq.com/cn/news/2011/06/xxb-maven-9-package 要点: 1. 打出可执行的jar包, 2. 自定义打包

  3. BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第9章节--client对象模型和REST APIs概览 client对象模型(CSOM)基础

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第9章节--client对象模型和REST APIs概览  client对象模型(CSOM)基础         在SP2 ...

  4. 115. distinct subsequence leetcode python

    Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...

  5. 一些绕过waf的笔记

    转自:http://fuck.0day5.com/archives/622.html 一.各种编码绕过1. ? 1 2 ?id=1 union select pass from admin limit ...

  6. Android Design Support Library(2)- TextInputLayout的使用

    原创文章,转载请注明 http://blog.csdn.net/leejizhou/article/details/50494634 这篇文章介绍下Android Design Support Lib ...

  7. Cardboard虚拟现实开发初步(一)

    Google Cardboard 虚拟现实眼镜开发初步(一) 虚拟现实技术简单介绍 不得不说这几年虚拟现实技术逐渐火热,伴随着虚拟现实设备的价格迅速平民化,越来越多的虚拟现实设备来到了我们眼前,也因此 ...

  8. python中@property的使用

    在绑定属性时,如果我们将属性直接暴露在外面,就可能导致属性被任意修改,有时候这个是我们不希望看到的如:设置学生的成绩 class Student(object): def __init__(self) ...

  9. Qt on Android:将Qt调试信息输出到logcat中

    版权全部 foruok .如需转载敬请注明出处(http://blog.csdn.net/foruok). 假设你在目标 Android 设备上执行了 Qt on Android 应用,你可能希望看到 ...

  10. rtems 4.11 IRQ (arm,beagle)

    arm IRQ入口在 cpukit/score/arm/arm_exec_interrupt.S 中,其中BSP最关心就是 bl bsp_interrupt_dispatch 这句,看看beagle ...