题目:
ZPS经过长期的努力争取,终于成为了0901班的领操员,他要带领0901班参加广播操比赛。现在0901班的队伍可以看作是一个n*n的点阵,每个人都站在格点上。现在作为领操员的ZPS站(0,0)点,他想知道如果0901班的队伍站齐了,他能看到多少个人的脸(假设每个人的身高相同,体积相同)。
sample input:
3
sample output:
5
分析:
对于一个点(x,y),当gcd(x,y)=1时,则便是一条新的斜率的直线,便可见。所以问题变成了求n,n之前互质的数的个数。这里用欧拉函数来做即可。(偷了一波管康的欧拉模板求φ).
代码:
var n:longint; ans:int64; procedure init; begin readln(n); end; function try(n:longint):int64; var i,j:longint; temp:int64; begin if n=1 then exit(0); temp:=n; j:=trunc(sqrt(n)); for i:=2 to j do if n mod i=0 then begin temp:=temp div i*(i-1); while n mod i=0 do n:=n div i; end; if n>1 then temp:=temp div n*(n-1); try:=temp; end; procedure main; var i:longint; begin ans:=3; for i:=1 to n-1 do inc(ans,try(i)*2); if n=1 then write(0) else write(ans); end; begin init; main; end.