JZOJ 7.10B组第一题 可见点数

题目:

ZPS经过长期的努力争取,终于成为了0901班的领操员,他要带领0901班参加广播操比赛。现在0901班的队伍可以看作是一个n*n的点阵,每个人都站在格点上。现在作为领操员的ZPS站(0,0)点,他想知道如果0901班的队伍站齐了,他能看到多少个人的脸(假设每个人的身高相同,体积相同)。

Input
一个正整数n。

Output
ZPS能看到多少个人的脸(当然他是看不到自己的脸的)。

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值