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 题目大意: ...
随机推荐
- bootstrap基础知识点YI
<!DOCTYPE html> <html lang="en"> ... </html> bootstrap页面都应该包含html5声明. 框架 ...
- Sublime Text 2使用技巧汇总
一.下载链接: Windows-64bit: http://pan.baidu.com/s/1o6QdKYu 其它版本请移步官网: http://www.sublimetext.com/ 二.破解Li ...
- Nginx 之三:nginx服务器模块、web请求处理机制及事件驱动模型、进程功能和进程间通信
一:Nginx的模块化结构设计: 1.核心模块:指的是nginx服务器运行当中必不可少的模块,这些模块提供了最基本最核心的服务,比如权限控制.进程管理.错误日志.事件驱动.正则表达式解析等,nginx ...
- Android开发 第一篇
关于android开发,new项目通知: 之前的new -> android project,现在更改为new -> android application project,同学们可以继续 ...
- 移植FreeModbus+ModbusMaster+STM32至RT-Thread(3、4阶段)
一.简介及进展 经过一个多月的努力,目前项目开发已进入最后阶段.虽然比预期时间有些延迟,但也收获不少,边工作边开源的效率确实还有待提高. 简单说下目前的进展吧 1.目前项目已经在Github中开源,大 ...
- AFNetworking GET和POST请求
GET请求 代码展示: 在storyBoard中每个请求关联一个Button #pragma mark - get请求 - (IBAction)getRequest:(id)sender { // 参 ...
- hdu 4737
题目链接 直接暴力,或运算只会越来越大 #include <cstdio> #include <cstring> using namespace std; #define N ...
- SQL Server 自学笔记
--★★★SQL语句本身区分大小写吗 --SQLServer 不区分大小写 --Oracle 默认是区分大小写的 --datetime的输入格式,2008-01-07输入进去后显示为1905-06-2 ...
- Hibernate + Spring (quartz) 整合懒(延迟)加载问题
开发项目的时候 在一个Job中执行了数据库操作, 用的是懒加载,但是如下错误 org.hibernate.LazyInitializationException: failed to lazily i ...
- Python之路Day9
摘要: 协程 Select\Poll\Epoll异步IO与事件驱动 Python连接MySQL数据库操作 RabbitMQ队列 Redis\Memcached缓存 Paramiko Twsited网络 ...