标题效果:定整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. [Android 性能优化系列]内存之提升篇--应用应该怎样管理内存

    大家假设喜欢我的博客,请关注一下我的微博,请点击这里(http://weibo.com/kifile),谢谢 转载请标明出处(http://blog.csdn.net/kifile),再次感谢 原文地 ...

  2. iOS_04_数据类型、常量、变量

    一.数据 1.什么是数据 * 生活中时时刻刻都在跟数据打交道,比如体重数据.血压数据.股价数据等.在我们使用计算机的过程中,会接触到各种各样的数据,有文档数据,图片数据,视频数据,还有聊天QQ产生的文 ...

  3. Android实现主动连接蓝牙耳机

    在Android程序中可以实现自动扫描蓝牙.配对蓝牙.建立数据通道. 蓝牙分不同类型,可以参考(http://gqdy365.iteye.com/admin/blogs/2229304) 可以入下面方 ...

  4. Learn from Architects of Buildings

     Learn from Architects of Buildings Keith Braithwaite Architecture is a social act and the material ...

  5. [Debug] Use Snippets to Store Behaviors in Chrome DevTools

    Using the Snippets tab in the source devtool you can define and run arbitrary pieces of code in your ...

  6. 关于Topsort

    Long time no see. 拓扑排序 英文名称:Topological-sort 别称:toposort or  topsort 拓扑排序是干什么的呢 对一个有向无环图(Directed Ac ...

  7. Deep Learning for Nature Language Processing --- 第四讲(下)

    A note on matrix implementations 将J对softmax的权重W和每一个word vector进行求导: 尽量使用矩阵运算(向量化).不要使用for loop. 模型训练 ...

  8. HDU 3791 二叉搜索树 (数据结构与算法实验题 10.2 小明) BST

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3791 中文题不说题意. 建立完二叉搜索树后进行前序遍历或者后序遍历判断是否一样就可以了. 跟这次的作业第 ...

  9. ZOJ 3168 Sort ZOJ7 水

    再水一发,舍友肿么还在睡T T. ---------------------------------舍友还在睡觉的分割线--------------------------------- http:/ ...

  10. PatentTips - High-performance AHCI Interface

    BACKGROUND OF THE INVENTION Various storage protocols for communicating with storage devices are kno ...