bzoj 2818 gcd 线性欧拉函数
2818: Gcd
Time Limit: 10 Sec Memory Limit: 256 MB
[Submit][Status][Discuss]
Description
给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的
数对(x,y)有多少对.
Input
一个整数N
Output
如题
Sample Input
Sample Output
HINT
hint
对于样例(2,2),(2,4),(3,3),(4,2)
1<=N<=10^7
思路:gcd(x,y)=p;p为素数;
gcd(x/p,y/p)==1;
一个p的贡献为1-(N/p),求前缀和意思;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000009
#define inf 999999999
#define esp 0.00000000001
//#pragma comment(linker, "/STACK:102400000,102400000")
const int N=1e5,M=1e7+;
ll p[M],ji;
bool vis[M];
ll phi[M];
void get_eular(int n)
{
ji = ;
memset(vis, true, sizeof(vis));
for(int i = ; i <= n; i++)
{
if(vis[i])
{
p[ji ++] = i;
phi[i] = i - ;
}
for(int j = ; j < ji && i * p[j] <= n; j++)
{
vis[i * p[j]] = false;
if(i % p[j] == )
{
phi[i * p[j]] = phi[i] * p[j];
break;
}
else
phi[i * p[j]] = phi[i] * phi[p[j]];
}
}
}
ll sumphi[M];
int main()
{
ll x,y,z,i,t;
get_eular();
sumphi[]=;
for(i=;i<=;i++)
sumphi[i]=sumphi[i-]+phi[i];
while(~scanf("%lld",&x))
{
ll ans=;
for(i=;p[i]<=x;i++)
ans+=*sumphi[x/p[i]]-;
printf("%lld\n",ans);
}
return ;
}
bzoj 2818 gcd 线性欧拉函数的更多相关文章
- bzoj 2818 GCD 数论 欧拉函数
bzoj[2818]Gcd Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Samp ...
- BZOJ 2818 GCD 【欧拉函数 || 莫比乌斯反演】
传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=2818 2818: Gcd Time Limit: 10 Sec Memory Limit ...
- BZOJ 2818 Gcd 线性欧拉筛(Eratosthenes银幕)
标题效果:定整N(N <= 1e7),乞讨1<=x,y<=N和Gcd(x,y)素数的数(x,y)有多少.. 思考:推,. 建立gcd(x,y) = p,然后,x / p与y / p互 ...
- BZOJ 2818 Gcd 线性欧拉
题意:链接 方法:线性欧拉 解析: 首先列一下表达式 gcd(x,y)=z(z是素数而且x,y<=n). 然后我们能够得到什么呢? gcd(x/z,y/z)=1; 最好还是令y>=x 则能 ...
- bzoj 2818 Gcd(欧拉函数 | 莫比乌斯反演)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2818 [题意] 问(x,y)为质数的有序点对的数目. [思路一] 定义f[i]表示i之 ...
- BZOJ 2818 GCD(欧拉函数)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37161 题意:gcd(x, y) = 质数, 1 <= x, ...
- 【BZOJ】2818: Gcd(欧拉函数+质数)
题目 传送门:QWQ 分析 仪仗队 呃,看到题后感觉很像上面的仪仗队. 仪仗队求的是$ gcd(a,b)=1 $ 本题求的是$ gcd(a,b)=m $ 其中m是质数 把 $ gcd(a,b)=1 $ ...
- HYSBZ 2818 Gcd【欧拉函数/莫比乌斯】
I - Gcd HYSBZ - 2818 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample In ...
- 【BZOJ】2818: Gcd(欧拉函数/莫比乌斯)
http://www.lydsy.com/JudgeOnline/problem.php?id=2818 我很sb的丢了原来做的一题上去.. 其实这题可以更简单.. 设 $$f[i]=1+2 \tim ...
随机推荐
- Windows Phone 有关独立存储(一)
private const string foldername = "temp1"; private const string filename = foldername + &q ...
- Android通知栏的高度获取
public static int getStatusBarHeight(Context context){ Class<?> c = null; Object obj = null; F ...
- mysql 5.7如何添加用户
MySQL5.7 添加用户.删除用户与授权 转自:https://www.cnblogs.com/xujishou/p/6306765.html mysql -uroot -proot MySQL5 ...
- mysql数据库LOAD DATA INFILE Syntax
1.LOAD DATA INFILE用来把一个文本文件里的内容高速写入到MySQL表里,它和SELECT ... INTO FILE的操作是对应的,一个导入.一个导出.使用LOAD DATA INFI ...
- ubuntu下安装运行colmap
从源码安装 colmap可以在主流的系统windows,mac,linux安装 从github上获取colmap的最新源码 git clone https://github.com/colmap/co ...
- windows 文件查找 大小:>250M
win7怎么快速查找大文件_百度经验 https://jingyan.baidu.com/article/acf728fd299ffff8e510a333.html
- Python量化教程 常用函数
# -*- coding: utf-8 -*- # @Author: fangbei # @Date: 2017-08-26 # @Original: price_str = '30.14, 29.5 ...
- socket协议和http协议性能对比
最近做了一次队列服务的性能测试,是通过两种协议windows socket和http分别往内存中写入url.对比哪种协议的效果更高,下图是测试结果.此次使用的工具是loadrunner.在压socke ...
- Python开发【Django】:中间件、CSRF
CSRF 1.概述 CSRF(Cross Site Request Forgery)跨站点伪造请求,举例来讲,某个恶意的网站上有一个指向你的网站的链接,如果某个用户已经登录到你的网站上了,那么当这个用 ...
- macOS Sierra 10.12版本 显示隐藏文件
1.显示隐藏文件 打开Terminal 输入:defaults write com.apple.finder AppleShowAllFiles -bool true 再输入: killall Fin ...