2818: Gcd
Time Limit: 10 Sec Memory Limit: 256 MB
Submit: 1633 Solved: 724
[Submit][Status]
Description
给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的
数对(x,y)有多少对.
Input
一个整数N
Output
如题
Sample Input
4
Sample Output
4
HINT
hint
对于样例(2,2),(2,4),(3,3),(4,2)
1<=N<=10^7
Source
求gcd(x,y)==prime[k] 對數(1<=x,y<=n)
枚舉質數p,求gcd(x,y)==1, (1<=x,y<=n/p)
設sphi(k)表示gcd(x,y)==1,(1<=x,y<=k),那麼,可以通過幾何法推導出sphi(k)=phi(k)*2+sphi(k-1)
然後此題可解。
时间: 2024-10-07 02:09:01