POJ 3090 Visible Lattice Points 欧拉函数
链接: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 欧拉函数的更多相关文章
- [poj 3090]Visible Lattice Point[欧拉函数]
找出N*N范围内可见格点的个数. 只考虑下半三角形区域,可以从可见格点的生成过程发现如下规律: 若横纵坐标c,r均从0开始标号,则 (c,r)为可见格点 <=>r与c互质 证明: 若r与c ...
- POJ3090 Visible Lattice Points 欧拉函数
欧拉函数裸题,直接欧拉函数值乘二加一就行了.具体证明略,反正很简单. 题干: Description A lattice point (x, y) in the first quadrant (x a ...
- 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5636 Accepted: ...
- POJ 3090 Visible Lattice Points 【欧拉函数】
<题目链接> 题目大意: 给出范围为(0, 0)到(n, n)的整点,你站在(0,0)处,问能够看见几个点. 解题分析:很明显,因为 N (1 ≤ N ≤ 1000) ,所以无论 N 为多 ...
- POJ 3090 Visible Lattice Points | 其实是欧拉函数
题目: 给一个n,n的网格,点可以遮挡视线,问从0,0看能看到多少点 题解: 根据对称性,我们可以把网格按y=x为对称轴划分成两半,求一半的就可以了,可以想到的是应该每种斜率只能看到一个点 因为斜率表 ...
- poj 3090 Visible Lattice Points(离线打表)
这是好久之前做过的题,算是在考察欧拉函数的定义吧. 先把欧拉函数讲好:其实欧拉函数还是有很多解读的.emmm,最基础同时最重要的算是,¢(n)表示范围(1, n-1)中与n互质的数的个数 好了,我把规 ...
- [poj] 3090 Visible Lattice Points
原题 欧拉函数 我们发现,对于每一个斜率来说,这条直线上的点,只有gcd(x,y)=1时可行,所以求欧拉函数的前缀和.2*f[n]+1即为答案. #include<cstdio> #def ...
- POJ3090 Visible Lattice Points 欧拉筛
题目大意:给出范围为(0, 0)到(n, n)的整点,你站在原点处,问有多少个整点可见. 线y=x和坐标轴上的点都被(1,0)(0,1)(1,1)挡住了.除这三个钉子外,如果一个点(x,y)不互质,则 ...
- POJ 3090 Visible Lattice Points (ZOJ 2777)
http://poj.org/problem?id=3090 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1777 题目大意: ...
随机推荐
- BZOJ 1856: [Scoi2010]字符串( 组合数 )
求(0,0)->(n,m)且在直线y=x下方(可以在y=x上)的方案数...同 http://www.cnblogs.com/JSZX11556/p/4908648.html --------- ...
- 高级UNIX环境编程4 文件和目录
#include<sys/stat.h> stat fstat lstat fchmod 对已打开的文件操作
- CSS3 transform制作的漂亮的滚动式导航
模拟这个做的 不过实现的没有别人那么好 http://www.creativetier.com/products/modern-menu-3/vertical.html 关于transform 看这 ...
- Delphi 编写系统服务(服务控制线程:开始,暂停,继续,停止)
打开Delphi 7,新建,选择Other->Service Application 修改属性中Name和DisplayName,Name是Service的名称,决定着进程的标识,Display ...
- mongodb 限制ip访问
<pre name="code" class="python">一.限制访问IP和端口 MongoDB可以限制只允许某一特定IP来访问,只要在启动时 ...
- nginx学习六 高级数据结构之双向链表ngx_queue_t
1 ngx_queue_t简单介绍 ngx_queue_t是nginx提供的一个轻量级的双向链表容器,它不负责存储数据,既不提供数据的内存分配.它仅仅有两个指针负责把数据链入链表.它跟stl提供的qu ...
- highchats与php结合生成动态统计图
series: [{ type: 'pie', name: 'Browser share', data: [ ['Firefox', 45.0], ['IE', 26.8], { name: 'Chr ...
- CSS的三种样式:内联式,嵌入式,外部式以及他们的优先级
从CSS 样式代码插入的形式来看基本能够分为下面3种:内联式.嵌入式和外部式三种. 1:内联式css样式表就是把css代码直接写在现有的HTML标签中,如以下代码: <p style=" ...
- ListView下拉刷新及上拉更多两种状态
一.前言: 很多应用都会用到ListView,当然如果是iOS就会用UITableViewController,这两个控件在不同的OS上,功能是一样的,只是有些细微的不同(iOS的UITableVie ...
- Xcode5 创建模板和UIView 关联XIB
转自:http://www.cnblogs.com/china-ldw/p/3533896.html 在做ios应用开发的过程,难免遇到要创建 子view 和 自定义view的时候,归根到底,我们需要 ...