P8 Visible Lattice Points
来源:互联网 发布:2017年大学生毕业数据 编辑:程序博客网 时间:2024/04/28 23:18
Time Limit:1000ms, Memory Limit:65536KB
Description
A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) to (x, y) does not pass through any other lattice point. For example, the point (4, 2) is not visible since the line from the origin passes through (2, 1). The figure below shows the points (x, y) with 0 ≤ x, y ≤ 5 with lines from the origin to the visible points.
图片链接:http://blog.sina.com.cn/s/blog_4a7304560101ajjf.html
Write a program which, given a value for the size, N, computes the number of visible points (x, y) with 0 ≤ x, y ≤ N.
Input
The first line of input contains a single integer C (1 ≤ C ≤ 1000) which is the number of datasets that follow.
Each dataset consists of a single line of input containing a single integer N (1 ≤ N ≤ 1000), which is the size.
Output
For each dataset, there is to be one line of output consisting of: the dataset number starting at 1, a single space, the size, a single space and the number of visible points for that size.
Sample Input
3
2
4
231
Sample Output
1 2 5
2 4 13
3 231 32549
分析:
主要求法:是用两个互质因数的求解,我个人认为有求最大公约数的方法进行求解!!!
#include<iostream>#include<math.h>using namespace std;int main(){ int n,m,k=0; int x,y; int count; int prime(int,int );cin>>m; while(m--) { cin>>n; count=2; k++; if(n==1) cout<<k<<" "<<n<<" "<<"3"; else if(n>1) { for(x=1;x<=n;x++) { for(y=1;y<=n;y++) { if(prime(x,y)==1) count++; } } cout<<k<<" "<< n<<" "<<count; // cout<<endl; } } return 0;}int prime(int u,int v){int t,r;r=1;if(v>u){ t=u;u=v;v=t;} while((r=u%v)!=0) { u=v; v=r; } return v; }
- P8 Visible Lattice Points
- pku3090 Visible Lattice Points
- poj3090-Visible Lattice Points
- poj3090-Visible Lattice Points
- Visible Lattice Points
- poj3090 Visible Lattice Points
- [POJ3090]Visible Lattice Points
- POJ3090 Visible Lattice Points
- Visible Lattice Points
- Visible Lattice Points POJ
- Visible Lattice Points POJ
- pku 3090 Visible Lattice Points
- POJ 3090 Visible Lattice Points
- ZOJ2777 POJ2090 Visible Lattice Points
- poj 3090 Visible Lattice Points
- poj 3090 Visible Lattice Points
- POJ 3090 Visible Lattice Points
- ZOJ 2777 Visible Lattice Points
- 基于空间金字塔池化的卷积神经网络物体检测
- 喷水装置(一)
- 二叉树遍历总结
- 美女购物
- [POJ 1759] Garland (二分)
- P8 Visible Lattice Points
- thinkpad x260在ubuntu 14.04lts wifi驱动安装 ( ubuntu iwlwifi驱动 都可行 )
- STM8的数据@near @tiny定义
- 奇怪的排序
- python 装饰器
- CString转string
- java类型存储方式理解
- new关键字的理解-问题型
- 重载和重写的区别