[POJ3090] 可见点
来源:互联网 发布:半月板损伤 知乎 编辑:程序博客网 时间:2024/05/16 01:27
题目描述
第一象限的坐标点(x,y)(x,y都是整数,x>=0且y>=0),从点(0,0)到点(x,y)画一条线段,如果这条线段不经过其他整数坐标点,那么称作点(x,y)是可见的。例如,点(4,2)是不可见的,因为线段经过点(2,1)。下图中显示了区域0<=x<=5,0<=y<=5内的所有可见点,以及从点(0,0)到这些可见点的线段。
给出一个可见点N,编写一个程序,计算在区域0<=x<=N,0<=y<=N内可见点的数目。
输入格式
输入文件仅一个数N。
输出格式
输出文件仅一个数,即该区域可见点数。
样例数据
样例输入
4
样例输出
13
数据规模和约定
对于 30% 的数据,1≤N≤1000
对于 100% 的数据,1≤N≤40000
题目分析
类似挑选士兵
不过观察者站在(1,1),因此答案须+2
源代码
#include<algorithm>#include<iostream>#include<iomanip>#include<cstring>#include<cstdlib>#include<vector>#include<cstdio>#include<cmath>#include<queue>using namespace std;inline const long long Get_Int() { long long num=0,bj=1; char x=getchar(); while(x<'0'||x>'9') { if(x=='-')bj=-1; x=getchar(); } while(x>='0'&&x<='9') { num=num*10+x-'0'; x=getchar(); } return num*bj;}long long n,f[1000005],Phi[1000005];void Euler_Table(int n) { //筛选法求欧拉函数 memset(Phi,0,sizeof(Phi)); Phi[1]=1; for(int i=2; i<=n; i++) if(Phi[i]==0) for(int j=i; j<=n; j+=i) { if(Phi[j]==0)Phi[j]=j; Phi[j]=Phi[j]/i*(i-1); }}int t;int main() { t=Get_Int(); Euler_Table(2000); f[1]=1; for(int j=2; j<=2000; j++)f[j]=f[j-1]+Phi[j]; for(int i=1; i<=t; i++) { n=Get_Int(); printf("%d %lld %lld\n",i,n,f[n]*2+1); //所有gcd为1的都能看到,对角线对称*2,(1,1)可以看见+1 } return 0;}
0 0
- [POJ3090] 可见点
- poj3090
- POJ3090
- POJ3090
- WOJ1420-可见点
- WOJ Problem 1420 - 可见点
- poj3090(eular)
- Activity真正“可见”的时间点
- 译:Activity真正“可见”的时间点
- poj3090-Visible Lattice Points
- poj3090-Visible Lattice Points
- [POJ3090]欧拉公式
- poj3090 Visible Lattice Points
- [POJ3090]Visible Lattice Points
- POJ3090 Visible Lattice Points
- 【WOJ-1420-可见点】采用数论知识求互质对
- Visible Lattice Points(poj3090)
- Visible Lattice Points(POJ3090)
- TextVeiw显示丰富的文本
- 高并发Web系统架构解决方案的几点思路
- cocos2d - JS 实现翻页效果
- uploadify使用总结
- 数据结构之AVL树
- [POJ3090] 可见点
- 【Latex】制作演示文档或者课程报告 - 制作演示文档(二)
- Java设计模式之工厂模式
- chrome 播放视频提示 adobe flash player已过期或者adobe flash player 没有安装
- 用css来设置div的样式
- 软件开发方法
- spa单页的优缺点
- Activity全面解析
- 前置声明与C++头文件互相包含导致的error: 'xxx' does not name a type问题