标题效果:定整N(N <= 1e7),乞讨1<=x,y<=N和Gcd(x,y)素数的数(x,y)有多少.、

思考:推,。

建立gcd(x,y) = p,然后,x / p与y / p互素

问题就转化成了N / p中有多少个数互质,然后累加就能够了.

=>对于随意a,b,a <= N / p,b <= N / p,且a与b互质

=>gcd(a,b) == 1

如今问题就非常明显了。看到这个形式就非常easy想到欧拉函数。求一下phi,算一下前缀和,累加。

注意这里求欧拉一定要线性的,1qw的数据。nloglogn都非常悬。

CODE:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAX 10000010
using namespace std; bool not_prime[MAX];
int prime[MAX],primes;
long long phi[MAX],ans; int n; inline void Eratosthenes(); int main()
{
cin >> n;
Eratosthenes();
for(int i = 2;i <= n; ++i)
phi[i] += phi[i - 1];
for(int i = 1;i <= primes; ++i)
ans += phi[n / prime[i]];
cout << (ans << 1) - primes << endl;
return 0;
} inline void Eratosthenes()
{
phi[1] = 1;
for(int i = 2;i <= n; ++i) {
if(!not_prime[i])
prime[++primes] = i,phi[i] = i - 1;
for(int j = 1;j <= primes && prime[j] * i <= n; ++j) {
not_prime[i * prime[j]] = true;
if(i % prime[j] == 0) {
phi[i * prime[j]] = phi[i] * prime[j];
break;
}
else phi[i * prime[j]] = phi[i] * (prime[j] - 1);
}
}
}

版权声明:本文博主原创文章。博客,未经同意不得转载。

BZOJ 2818 Gcd 线性欧拉筛(Eratosthenes银幕)的更多相关文章

  1. BZOJ 2818 Gcd 线性欧拉

    题意:链接 方法:线性欧拉 解析: 首先列一下表达式 gcd(x,y)=z(z是素数而且x,y<=n). 然后我们能够得到什么呢? gcd(x/z,y/z)=1; 最好还是令y>=x 则能 ...

  2. bzoj 2818 gcd 线性欧拉函数

    2818: Gcd Time Limit: 10 Sec  Memory Limit: 256 MB[Submit][Status][Discuss] Description 给定整数N,求1< ...

  3. bzoj 2818 GCD 数论 欧拉函数

    bzoj[2818]Gcd Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Samp ...

  4. BZOJ 2818 GCD 【欧拉函数 || 莫比乌斯反演】

    传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=2818 2818: Gcd Time Limit: 10 Sec  Memory Limit ...

  5. bzoj 2818 Gcd(欧拉函数 | 莫比乌斯反演)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2818 [题意] 问(x,y)为质数的有序点对的数目. [思路一] 定义f[i]表示i之 ...

  6. BZOJ 2818 GCD(欧拉函数)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37161 题意:gcd(x, y) = 质数, 1 <= x, ...

  7. POJ2909_Goldbach's Conjecture(线性欧拉筛)

    Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one p ...

  8. 【BZOJ】2818: Gcd(欧拉函数+质数)

    题目 传送门:QWQ 分析 仪仗队 呃,看到题后感觉很像上面的仪仗队. 仪仗队求的是$ gcd(a,b)=1 $ 本题求的是$ gcd(a,b)=m $ 其中m是质数 把 $ gcd(a,b)=1 $ ...

  9. hdu3572线性欧拉筛

    用线性筛来筛,复杂度O(n) #include<bits/stdc++.h> #include<ext/rope> #define fi first #define se se ...

随机推荐

  1. C#委托与事件(生动故事)

    [委托] 1,工人Peter按工作步骤向老板报告的程序. 程序: using System; using System.Collections.Generic; using System.Linq; ...

  2. 如何把别人的原理图和pcb图建立一个完整的工程

    这里是我从网友那里下载的pcb图和原理图 我们怎么通过这两个文件建立一个完整的工程 我们选中pcb图文件,通过下面的操作,就可以导出pcb封装库: 同样的方法,我选中pcb图,然后用下面图的方法,就可 ...

  3. 关于DOM的有关总结

    1.获取DOM元素 document.getElementById()  通过id获取DOM元素 document.getElementsByClassName() 通过类名获取DOM元素 docum ...

  4. [Web Security] Create a hash salt password which can stored in DB

    We cannot directly store user password in the database. What need to do is creating a hashed & s ...

  5. [D3] Create DOM Elements with D3 v4

    Change is good, but creating from scratch is even better. This lesson shows you how to create DOM el ...

  6. 从Unreal Engine 3到Unreal Engine 4

    Unreal Engine 4公布好长好长时间了.直到近期才有时间细致去看一下. TimSweeney老大一句话"IF YOU LOVE SOMETHING, SET IT FREE&quo ...

  7. python opencv3 —— 常用工具、辅助函数、绘图函数(图像添加文本、矩形等几何形状)

    1. cv2.hconcat().cv2.vconcat() 将从摄像头捕获的多个图像帧,横向(cv2.hconcat)或纵向(cv2.vconcat)拼接到一起,使得可以在一个 window 中进行 ...

  8. 9.11 Binder系统_分层

    1.Binder系统过程分析,情景分析 server提供服务 (1)addService(服务名称,xxx)执行后会导致binder驱动在server的内核空间为服务创建一个binder_node结构 ...

  9. js中JSON的解析(将json字符串转化为对象)和序列化(将对象转化为json字符串)(函数的功能一般都挺全的,需要的时候去查看完整函数)

    js中JSON的解析(将json字符串转化为对象)和序列化(将对象转化为json字符串)(函数的功能一般都挺全的,需要的时候去查看完整函数) 一.总结 1.JSON解析:JSON.parse(myJS ...

  10. Centos配置java环境

    安装jdk JDK 是开发Java程序必须安装的软件,我们查看一下 yum 源里面的 JDK:yum list java* 选择适合本机的JDK,并安装:yum install java-1.7.0- ...