P8 Visible Lattice Points
P8 Visible Lattice Points
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的更多相关文章
- 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5636 Accepted: ...
- spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演
SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...
- poj 3060 Visible Lattice Points
http://poj.org/problem?id=3090 Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Tota ...
- Spoj 7001 Visible Lattice Points 莫比乌斯,分块
题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193 Visible Lattice Points Time L ...
- 【POJ】3090 Visible Lattice Points(欧拉函数)
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7705 Accepted: ...
- POJ3090 Visible Lattice Points
/* * POJ3090 Visible Lattice Points * 欧拉函数 */ #include<cstdio> using namespace std; int C,N; / ...
- Visible Lattice Points (莫比乌斯反演)
Visible Lattice Points 题意 : 从(0,0,0)出发在(N,N,N)范围内有多少条不从重合的直线:我们只要求gcd(x,y,z) = 1; 的点有多少个就可以了: 比如 : 点 ...
- SPOJ1007 VLATTICE - Visible Lattice Points
VLATTICE - Visible Lattice Points no tags Consider a N*N*N lattice. One corner is at (0,0,0) and th ...
- SPOJ 7001. Visible Lattice Points (莫比乌斯反演)
7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0, ...
随机推荐
- A. Launch of Collider Codeforces Round #363 (Div2)
A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 阅读http://zh.lucida.me/有感
lucida大神本科毕业于大工,研究生毕业于北航,有这样的学历在社会上混就已经绰绰有余了,但是lucida神并不满足,刻苦努力,拼搏进取,最后进入google london工作,曾经一度在micros ...
- 《Windows驱动开发技术详解》之自定义StartIO
自定义StartIO 系统定义的StartIO队列只能使用一个队列(DDK提供的StartIO内部只有一个队列),这个队列将所有的IRP进行处理化.例如,读.写操作都会混在一起进行串行处理.然而,有时 ...
- nefu 1029 字符串
Description 给定一个字符串,现在要你从这个字符串中找到第一个只出现一次的字符 ,很简单吧! 快敲代码,动作! Input 多组输入,每行一个字符串(小写字母a~z)字符串长度不超过50 O ...
- 【python问题系列--1】SyntaxError:Non-ASCII character '\xe5' in file kNN.py on line 2, but no encoding declared;
因为Python在默认状态下不支持源文件中的编码所致.解决方案有如下三种: 一.在文件头部添加如下注释码: # coding=<encoding name> 例如,可添加# coding= ...
- angular中的ng-bind-html指令和$sce服务
angular js的强大之处之一就是他的数据双向绑定这一牛B功能,我们会常常用到的两个东西就是ng-bind和针对form的ng-model.但在我们的项目当中会遇到这样的情况,后台返回的数据中带有 ...
- shell:crontab
crontab */1 * * * * (cd /home/q/system/project; /usr/bin/lockf -t 0 /tmp/discuz_bbs_audit.lock /usr/ ...
- 【翻译】Longest Palindromic Substring 最长回文子串
原文地址: http://articles.leetcode.com/2011/11/longest-palindromic-substring-part-i.html 转载请注明出处:http:// ...
- IE下单选按钮隐藏后点击对应label无法选中的bug解决
项目中,有时候填写表单我们的选项会隐藏掉radio或者checkbox,而只显示给用户对应的文字选择,如果用户点击label选择时,在FF/Chrome等标准浏览器中隐藏掉的radio/checkbo ...
- 清除number输入框的上下箭头
<input type="number"/> 在chrome,firefox,safari浏览器上输入框右侧会有上下箭头 方法1: <input type=&qu ...