POJ 3090 欧拉函数递推
2013-07-28 11:07
381 查看
题意:为多少个点与原点连线不经过其他点。
首先ans[1]=3,不经过其他点也就是(x,y)点的gcd(x,y)=1,也就是x,y,互素。所以就是每一行上的个数为phi(n)*2因为行和列都算上就是两倍关系。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 1000008
long long phi[maxn];
void getphi()
{
for(int i=1; i<maxn; i++) phi[i]=i;
for(int i=2; i<maxn; i+=2) phi[i]>>=1;
for(int i=3; i<maxn; i+=2)
if(phi[i]==i)
{
for(int j=i; j<maxn; j+=i)
phi[j]=phi[j]/i*(i-1);
}
phi[1]=3;
for(int i=2; i<maxn; i++)
phi[i]=phi[i-1]+2*phi[i];
}
int main()
{
getphi();
int n,ca=0,t;
scanf("%d",&t);
while(t--)
scanf("%d",&n),
printf("%d %d %lld\n",++ca,n,phi
);
return 0;
}
首先ans[1]=3,不经过其他点也就是(x,y)点的gcd(x,y)=1,也就是x,y,互素。所以就是每一行上的个数为phi(n)*2因为行和列都算上就是两倍关系。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 1000008
long long phi[maxn];
void getphi()
{
for(int i=1; i<maxn; i++) phi[i]=i;
for(int i=2; i<maxn; i+=2) phi[i]>>=1;
for(int i=3; i<maxn; i+=2)
if(phi[i]==i)
{
for(int j=i; j<maxn; j+=i)
phi[j]=phi[j]/i*(i-1);
}
phi[1]=3;
for(int i=2; i<maxn; i++)
phi[i]=phi[i-1]+2*phi[i];
}
int main()
{
getphi();
int n,ca=0,t;
scanf("%d",&t);
while(t--)
scanf("%d",&n),
printf("%d %d %lld\n",++ca,n,phi
);
return 0;
}
相关文章推荐
- poj 3090 (欧拉函数,找规律)
- poj 2478/3090 欧拉函数应用(Farey 序列/斜率判重)
- Poj3090 Visible Lattice Points 欧拉函数求和
- poj 2478 Farey Sequence 欧拉函数递推打表
- poj 2478 Farey Sequence(递推求欧拉函数)
- POJ 3090 Visible Lattice Points(欧拉函数)
- POJ 3090 欧拉函数
- POJ 3090 Visible Lattice Points 欧拉函数运用
- Poj 3090 Visible Lattice Points(欧拉函数)
- POJ3090_Visible Lattice Points【欧拉函数】
- POJ 3090 Visible Lattice Points | 其实是欧拉函数
- poj_3090_欧拉函数
- POJ_3090_Visible Lattice Point_欧拉函数
- POJ 2478 Farey Sequence & POJ 3090 Visible Lattice Points (欧拉函数)
- [poj 3090]Visible Lattice Point[欧拉函数]
- POJ 3090 ZOJ 2777 UVALive 3571 Visible Lattice Points(用递推比用欧拉函数更好)
- poj 3090 欧拉函数简单应用
- 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points
- poj 3090 Visible Lattice Points 欧拉函数打表求和
- POJ 3090 Visible Lattice Points(欧拉函数)