【BZOJ2818】Gcd (欧拉函数)
网址:http://www.lydsy.com/JudgeOnline/problem.php?id=2818
一道数论裸题,欧拉函数前缀和搞一下就行了。
小于n的gcd为p的无序数对,就是phi(1~n/p)的和,因为如果gcd(x,y)=p那么必有gcd(x/p,y/p)=1
转化成有序数对就可以把无序数对的个数*2-1(减1是因为有一个数对是(p,p))
代码:
var p,phi:array[..]of longint;
s:array[..]of int64;
b:array[..]of boolean;
n,m,i,j,k,t:longint;
ans:int64;
begin
read(n); t:=;
for i:= to n do b[i]:=true;
b[]:=false; phi[]:=;
for i:= to n do begin
if b[i] then begin
phi[i]:=i-; inc(t); p[t]:=i;
end;
for j:= to t do begin
if i*p[j]>n then break;
b[i*p[j]]:=false;
if i mod p[j]= then begin
phi[i*p[j]]:=phi[i]*p[j];
break;
end;
phi[i*p[j]]:=phi[i]*phi[p[j]];
end;
end;
ans:=;
for i:= to n do
s[i]:=s[i-]+phi[i];
for i:= to t do
ans:=ans+s[n div p[i]]*-;
writeln(ans);
end.
【BZOJ2818】Gcd (欧拉函数)的更多相关文章
- Bzoj-2818 Gcd 欧拉函数
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2818 题意:给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x ...
- BZOJ2818: Gcd 欧拉函数求前缀和
给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 如果两个数的x,y最大公约数是z,那么x/z,y/z一定是互质的 然后找到所有的素数,然后用欧拉函数求一 ...
- BZOJ2818: Gcd 欧拉函数
Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 Sam ...
- 洛谷P2568 GCD (欧拉函数/莫比乌斯反演)
P2568 GCD 题目描述 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 输入输出格式 输入格式: 一个整数N 输出格式: 答案 输入输出样例 输入 ...
- BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 4436 Solved: 1957[Submit][Status][Discuss ...
- POJ 2773 Happy 2006【GCD/欧拉函数】
根据欧几里德算法,gcd(a,b)=gcd(a+b*t,b) 如果a和b互质,则a+b*t和b也互质,即与a互质的数对a取模具有周期性. 所以只要求出小于n且与n互质的元素即可. #include&l ...
- HDU 2588 GCD (欧拉函数)
GCD Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Status De ...
- hdu2588 gcd 欧拉函数
GCD Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDU 1695 GCD 欧拉函数+容斥定理
输入a b c d k求有多少对x y 使得x在a-b区间 y在c-d区间 gcd(x, y) = k 此外a和c一定是1 由于gcd(x, y) == k 将b和d都除以k 题目转化为1到b/k 和 ...
- HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- 关于 JavaScript 学习 —— 好的博客或者网站推荐
作者:Tw93链接:https://www.zhihu.com/question/19651401/answer/46211739来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...
- Win7 sql2005附加数据库失败 错误5120
错误信息如下: 标题: Microsoft SQL Server Management Studio Express------------------------------ 附加数据库 对于 ...
- Python抓取网页并保存为PDF
https://blog.csdn.net/shenwanjiang111/article/details/67634794
- joisino's travel
D - joisino's travel Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement T ...
- Happy Necklace(矩阵快速幂)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submissi ...
- event对象及各种事件
事件(event) event对象 (1)什么是event对象? Event 对象代表事件的状态,比如事件在其中发生的元素.键盘按键的状态.鼠标的位置.鼠标按钮的状态.事件通常与函数结合使用,函数不会 ...
- ajax异步请求分页显示
html代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...
- Clustered and Secondary Indexes
Clustered and Secondary Indexes secondary index A type of InnoDB index that represents a subset of t ...
- Linux中的系统默认日志
/var/log/cron 记录了系统定时任务相关的日志 /var/log/cups 记录了打印信息的日志 /var/log/dmesg 记录了系统在开机时内核自检的信息,可以通过dmesg命令直接查 ...
- 解决后台无法进入提示DedeCMS Error: (PHP 5.3 and above) Please set 'request_order' ini value
最近小美眉的网站被盯上了,被添加了非常多的dubo页面,删除了5w多个文件,但还是不停的增加,因为网站权重还可以,很多都被收录了,结果可想而知,ytkah帮她迁移,在迁移网站时遇到了一些问题,后台登录 ...