GCD - Extreme (II) UVA - 11426 欧拉函数_数学推导
Code:
#include<cstdio>
using namespace std;
const int maxn=4000005;
const int R=4000002;
const int N=4000002;
long long sumv[maxn],f[maxn];
int phi[maxn],prime[maxn],vis[maxn];
void solve(){
phi[1]=1;
int cnt=0;
for(int i=2;i<=R;++i){
if(!vis[i])prime[++cnt]=i,phi[i]=i-1;
for(int j=1;j<=cnt&&prime[j]*i<=R;++j){
vis[prime[j]*i]=1;
if(i%prime[j]!=0)phi[i*prime[j]]=phi[i]*(prime[j]-1);
else{
phi[i*prime[j]]=phi[i]*prime[j];
break;
}
}
}
for(int i=1;i<N;++i)
for(int j=i*2;j<N;j+=i)
f[j]+=i*phi[j/i];
for(int i=1;i<N;++i)
sumv[i]=sumv[i-1]+f[i];
}
int main(){
solve();
while(1){
int n;scanf("%d",&n);
if(!n)break;
printf("%lld\n",sumv[n]);
}
return 0;
}
GCD - Extreme (II) UVA - 11426 欧拉函数_数学推导的更多相关文章
- GCD - Extreme (II) UVA - 11426 欧拉函数与gcd
题目大意: 累加从1到n,任意两个数的gcd(i,j)(1=<i<n&&i<j<=n). 题解:假设a<b,如果gcd(a,b)=c.则gcd(a/c,b ...
- UVa 11426 (欧拉函数 GCD之和) GCD - Extreme (II)
题意: 求sum{gcd(i, j) | 1 ≤ i < j ≤ n} 分析: 有这样一个很有用的结论:gcd(x, n) = i的充要条件是gcd(x/i, n/i) = 1,因此满足条件的x ...
- GCD - Extreme (II) UVA - 11426(欧拉函数!!)
G(i) = (gcd(1, i) + gcd(2, i) + gcd(3, i) + .....+ gcd(i-1, i)) ret = G(1) + G(2) + G(3) +.....+ G(n ...
- UVA 11426 (欧拉函数&&递推)
题意:给你一个数N,求N以内和N的最大公约数的和 解题思路: 一开始直接想暴力做,4000000的数据量肯定超时.之后学习了一些新的操作. 题目中所要我们求的是N内gcd之和,设s[n]=s[n-1] ...
- UVA - 11426 欧拉函数(欧拉函数表)
题意: 给一个数 N ,求 N 范围内所有任意两个数的最大公约数的和. 思路: f 数组存的是第 n 项的 1~n-1 与 n 的gcd的和,sum数组存的是 f 数组的前缀和. sum[n]=f[1 ...
- GCD - Extreme (II) UVA - 11426 数学
Given the value of N , you will have to nd the value of G . The de nition of G is given below: G = i ...
- F - GCD - Extreme (II) UVA - 11426
Given the value of N, you will have to find the value of G. The definition of G is given below:
- HDU5780 gcd (BestCoder Round #85 E) 欧拉函数预处理——分块优化
分析(官方题解): 一点感想: 首先上面那个等式成立,然后就是求枚举gcd算贡献就好了,枚举gcd当时赛场上写了一发O(nlogn)的反演,写完过了样例,想交发现结束了 吐槽自己手速慢,但是发了题解后 ...
- 【BZOJ2818】Gcd(莫比乌斯反演,欧拉函数)
题意:给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对 1<=N<=10^7 思路:莫比乌斯反演,同BZOJ2820…… ; ..max]of ...
随机推荐
- BZOJ 2150 部落战争 (二分图匹配)
题目大意:给你一个n*m的棋盘,有一些坏点不能走,你有很多军队,每支军队可以像象棋里的马一样移动,不过马是1*2移动的,而军队是r*c移动的,军队只能从上往下移动,如果一个点已经被一直军队经过,那么其 ...
- 代理上网环境配置docker私有库
最后更新时间:2018年12月27日 Docker使用代理上网去 pull 各类 images,需要做如下配置: 创建目录: /etc/systemd/system/docker.service.d ...
- unity 获取UGUI中的Text字的坐标
using System.Collections; using UnityEngine; using UnityEngine.UI; public class TextMoveHelper : Mon ...
- tomcat的连接数与线程池
在使用tomcat时,经常会遇到连接数.线程数之类的配置问题,要真正理解这些概念,必须先了解Tomcat的连接器(Connector). 在前面的文章中写到过:Connector的主要功能,是接收连接 ...
- COGS——T 1168. 机器调度
http://www.cogs.pro/cogs/problem/problem.php?pid=1168 ★★ 输入文件:machine.in 输出文件:machine.out 简单对比 ...
- test文件夹,测试类是放在src目录下的,test测试代码是代码啊,当然要放在代码文件夹下
test文件夹,测试类是放在src目录下的,test测试代码是代码啊,当然要放在代码文件夹下 Maven的标准工程结构 Maven的标准工程结构如下: |-- pom.xml(maven的核心配置文件 ...
- POJ-3264-Balanced Lineup-单点更新
题目链接:id=3264">http://poj.org/problem? id=3264 这是一个单点更新的模板题,就不详解了,HDU敌兵布阵那题我有详解:链接:http://blo ...
- 小记 SqlHelper
using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Web;u ...
- HDU 1392 凸包子
Surround the Trees Problem Description There are a lot of trees in an area. A peasant wants to buy a ...
- nyoj--914--Yougth的最大化(二分查找)
Yougth的最大化 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Yougth现在有n个物品的重量和价值分别是Wi和Vi,你能帮他从中选出k个物品使得单位重量的价值最 ...