UVA 11426 GCD - Extreme (II) (欧拉函数+筛法)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/O
题意是给你n,求所有gcd(i , j)的和,其中1<=i <j <n。
要是求gcd(n , x) = y的个数的话,那么就是求gcd(n/y , x/y) = 1的个数,也就是求n/y的欧拉函数。这里先预处理出欧拉函数,然后通过类似筛法的技巧筛选出答案累加起来。
#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = ;
typedef long long LL;
int p[MAXN];
LL a[MAXN]; void init() {
for(int i = ; i < MAXN ; i++)
p[i] = i;
for(int i = ; i < MAXN ; i++) {
if(p[i] == i) {
for(int j = i ; j < MAXN ; j += i)
p[j] = p[j] / i * (i - );
}
}
for(int i = ; i < MAXN ; i++) {
for(int j = * i ; j < MAXN ; j += i) {
a[j] += (LL)i * (LL)p[j / i];
}
}
for(int i = ; i < MAXN ; i++) {
a[i] = a[i] + a[i - ];
}
} int main()
{
init();
int n;
while(cin >> n && n) {
cout << a[n] << endl;
}
}
UVA 11426 GCD - Extreme (II) (欧拉函数+筛法)的更多相关文章
- UVA 11426 GCD - Extreme (II) 欧拉函数
分析:枚举每个数的贡献,欧拉函数筛法 #include <cstdio> #include <iostream> #include <ctime> #include ...
- 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) (欧拉函数打表)
题意:给一个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) 值为 ...
- 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 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 ...
随机推荐
- Effective C++学习笔记 条款04:确定对象被使用前已先被初始化
一.为内置类型对象进行手工初始化,因为C++不保证初始化它们. 二.对象初始化数据成员是在进入构造函数用户编写代码前完成,要想对数据成员指定初始化值,那就必须使用初始化列表. class A { pu ...
- RazorEngine 3.6.5.0
public class Person { public string Name { get; set; } public string Code { get; set; } } var templa ...
- 关于<img>标签与文字垂直居中
要让左边的图片与后面的文字居中,如下效果 HTML代码: <img class="iconCls" alt="最新客户端" src="${bas ...
- bzoj1877: [SDOI2009]晨跑
挺裸的最小费用最大流... #include<cstdio> #include<queue> #include<cstring> #include<iostr ...
- Drupal 7.31版本爆严重SQL注入漏洞
今早有国外安全研究人员在Twitter上曝出了Drupal 7.31版本的最新SQL注入漏洞,并给出了利用测试的EXP代码. 在本地搭建Drupal7.31的环境,经过测试,发现该利用代码可成功执行并 ...
- Can't dispatch DDM chunk 52454151: no handler defined
[2010-07-12 10:10:06 - Hello Google Android]ActivityManager: DDM dispatch reg wait timeout [2010-07- ...
- php yii框架使用MongoDb
1.安装 运行 php composer.phar require --prefer-dist yiisoft/yii2-mongodb or add "yiisoft/yii2-mongo ...
- POJ 1664 放苹果
放苹果 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24985 Accepted: 15908 Description ...
- Java [Leetcode 83]Remove Duplicates from Sorted List
题目描述: Given a sorted linked list, delete all duplicates such that each element appear only once. For ...
- 【C#学习笔记】List容器使用
using System; using System.Collections.Generic; namespace ConsoleApplication { class Program { stati ...