题目链接: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. c#课程设计---猜猜看游戏

    1:游戏要求 1. 随机显示 一个名字 与 若干张相片(如3张).选择正确的相片. 2. 记录老师对每一个学生的认识概率P.并依据认识概率,确定"猜猜看"游戏中学生出现的频率. 认 ...

  2. js 数组去重复

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. Interleaving String——是否由两个string交叉、DP

    Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = ...

  4. 利用MFC里面格式化函数也可以实现可变长度的问题

    直接粘代码: 1: CString str1;  //定义两个MFC里面的CString里面的字符串 2: CString str2; 3: str1.Format("(%d)", ...

  5. 关于layui-layer独立组件--弹出层

    官方下载文档链接:http://layer.layui.com/ =================================================================== ...

  6. Redis学习手册(List数据类型)(转)

    一.概述: 在Redis中,List类型是按照插入顺序排序的字符串链表.和数据结构中的普通链表一样,我们可以在其头部(left)和尾部(right)添加新的 元素.在插入时,如果该键并不存在,Redi ...

  7. Spring学习八----------Bean的配置之Resources

    © 版权声明:本文为博主原创文章,转载请注明出处 Resources 针对于资源文件的统一接口 -UrlResource:URL对应的资源,根据一个URL地址即可创建 -ClassPathResour ...

  8. Xenomai for Debian Jessie

    安装内核源码包 apt install linux-source-3.16 安装其他编译需要的工具: apt install build-essential libc-dev libc6-dev pk ...

  9. Codeforces 558(C、D、E)总结

    558C 题意:给你n个数,可对每一个数进行操作(乘2或者除以2).求最少的操作使得全部的数都相等. 思路 : dp[ t ] 表示全部的数转化到 t 所需的最少操作, vis[ t ] 表示有多少数 ...

  10. 世界更清晰,搜狐新闻客户端集成HUAWEI HiAI 亮相荣耀Play发布会!

    ​​6月6日,搭载有“很吓人”技术的荣耀Play正式发布,来自各个领域的大咖纷纷为新机搭载的惊艳技术站台打call,其中,搜狐公司董事局主席兼首席执行官张朝阳揭秘:华为和搜狐新闻客户端在硬件AI方面做 ...