链接:http://poj.org/problem?id=3090

题意:在坐标系中,从横纵坐标 0 ≤ x, y ≤
N中的点中选择点,而且这些点与(0,0)的连点不经过其它的点。

思路:显而易见,x与y仅仅有互质的情况下才会发生(0,0)与(x,y)交点不经过其它的点的情况,对于x,y等于N时,能够选择的点均为小于等于N而且与N互质的数,共Euler(N)个,而且不重叠。所以能够得到递推公式aa[i]=aa[i]+2*Euler(N)。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <ctype.h>
#include <algorithm>
#include <string>
#include <set>
#define PI acos(-1.0)
#define maxn 10005
#define INF 0x7fffffff
#define eps 1e-8
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
int aa[1005];
int Euler(int tot)
{
int num=tot;
for(int i=2; i<=tot; i++)
{
if(tot%i==0)
num=num/i*(i-1);
while(tot%i==0)
tot/=i;
}
return num;
}
void init()
{
aa[0]=0;
aa[1]=3;
for(int i=2; i<=1000; i++)
aa[i]=aa[i-1]+Euler(i)*2;
}
int main()
{
int T;
scanf("%d",&T);
init();
for(int ii=1; ii<=T; ii++)
{
int tot;
scanf("%d",&tot);
printf("%d %d %d\n",ii,tot,aa[tot]);
}
return 0;
}

POJ 3090 Visible Lattice Points 欧拉函数的更多相关文章

  1. [poj 3090]Visible Lattice Point[欧拉函数]

    找出N*N范围内可见格点的个数. 只考虑下半三角形区域,可以从可见格点的生成过程发现如下规律: 若横纵坐标c,r均从0开始标号,则 (c,r)为可见格点 <=>r与c互质 证明: 若r与c ...

  2. POJ3090 Visible Lattice Points 欧拉函数

    欧拉函数裸题,直接欧拉函数值乘二加一就行了.具体证明略,反正很简单. 题干: Description A lattice point (x, y) in the first quadrant (x a ...

  3. 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points

    Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5636   Accepted: ...

  4. POJ 3090 Visible Lattice Points 【欧拉函数】

    <题目链接> 题目大意: 给出范围为(0, 0)到(n, n)的整点,你站在(0,0)处,问能够看见几个点. 解题分析:很明显,因为 N (1 ≤ N ≤ 1000) ,所以无论 N 为多 ...

  5. POJ 3090 Visible Lattice Points | 其实是欧拉函数

    题目: 给一个n,n的网格,点可以遮挡视线,问从0,0看能看到多少点 题解: 根据对称性,我们可以把网格按y=x为对称轴划分成两半,求一半的就可以了,可以想到的是应该每种斜率只能看到一个点 因为斜率表 ...

  6. poj 3090 Visible Lattice Points(离线打表)

    这是好久之前做过的题,算是在考察欧拉函数的定义吧. 先把欧拉函数讲好:其实欧拉函数还是有很多解读的.emmm,最基础同时最重要的算是,¢(n)表示范围(1, n-1)中与n互质的数的个数 好了,我把规 ...

  7. [poj] 3090 Visible Lattice Points

    原题 欧拉函数 我们发现,对于每一个斜率来说,这条直线上的点,只有gcd(x,y)=1时可行,所以求欧拉函数的前缀和.2*f[n]+1即为答案. #include<cstdio> #def ...

  8. POJ3090 Visible Lattice Points 欧拉筛

    题目大意:给出范围为(0, 0)到(n, n)的整点,你站在原点处,问有多少个整点可见. 线y=x和坐标轴上的点都被(1,0)(0,1)(1,1)挡住了.除这三个钉子外,如果一个点(x,y)不互质,则 ...

  9. POJ 3090 Visible Lattice Points (ZOJ 2777)

    http://poj.org/problem?id=3090 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1777 题目大意: ...

随机推荐

  1. Value Categories

    Value categories Three primary categories primary categories mixed special Each C++ expression (an o ...

  2. Reverse Integer - Palindrome Number - 简单模拟

    第一个题目是将整数进行反转,这个题实现反转并不难,主要关键点在于如何进行溢出判断.溢出判断再上一篇字符串转整数中已有介绍,本题采用其中的第三种方法,将数字转为字符串,使用字符串比较大小的方法进行比较. ...

  3. php实现分页,上一页下一页

    首先学东西  要多看手册用php自带的函数  可以解决一些难解的问题 <?php /**  * Created by JetBrains PhpStorm.  * User: Administr ...

  4. Tortoisegit 记住用户名和密码

    Tortoisegit 记住用户名和密码方法: [Windows系统] 当你配置好git后,在 C:\Documents and Settings\Administrator\ 目录下有一个  .gi ...

  5. Java疯狂讲义(三)

  6. The reference to entity "characterEncoding" must end with the ';' delimiter

    数据源配置时加上编码转换格式后出问题了: The reference to entity "characterEncoding" must end with the ';' del ...

  7. Python web框架有哪些

    简单易学的web.py, 大型的django:文档最完善.市场占有率最高.招聘职位最多. Tornado 具体看:http://feilong.me/2011/01/talk-about-python ...

  8. 2014ACM/ICPC亚洲区鞍山赛区现场赛1009Osu!

    鞍山的签到题,求两点之间的距离除以时间的最大值.直接暴力过的. A - Osu! Time Limit:1000MS     Memory Limit:262144KB     64bit IO Fo ...

  9. 解决安装oracle后系统变慢问题

    Oracle数据库是一个很占资源的软件,光一个实例服务所占内存,根据其安装时分配的内存就至少要达到256MB以上,再加上其他附属服务,光内存就要占用物理内存的400M左右,虚拟内存也会有等值或更高的损 ...

  10. hadoop的WordCount样例

    package cn.lmj.mapreduce; import java.io.IOException; import java.util.Iterator; import org.apache.h ...