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, ...
随机推荐
- 关于LR监视Windows和linux的说明
一.监控windows系统: 1.监视连接前的准备工作 1)进入被监视windows系统,开启以下二个服务Remote Procedure Call(RPC) 和Remote Registry Ser ...
- CSS样式与选择器
CSS构造块的样式: 1. h1{color:red;background-color:yellow} 其中:h1是选择器,花括号内是声明部分.多个声明之间用分号隔开. 2.为样式规则添加注释:/* ...
- lldpcli 常用命令
1.查看周围的邻居列表 root@hbg:/# lldpcli show neighbors------------------------------------------------------ ...
- mvc Area相关技术
ASP.NET MVC中,是依靠某些文件夹以及类的固定命名规则去组织model实体层,views视图层和控制层的.如果是大规模的应用程序,经常会由不同功能的模块组成,而每个功能模块都由MVC中的三层所 ...
- Django:之安全、国际化和session
Django 安全 以下是关于Django安全的一些特征,它包括如何使基于Django的网站的一些建议. 关于安全的官方文档:https://docs.djangoproject.com/en/dev ...
- flash/flex 编译错误汇总
来源:http://blog.chinaunix.net/uid-366408-id-116463.html 代码 消息 说明 1000 对 %s 的引用不明确. 引用可能指向多项.例如,下面使用 ...
- ios中的关键词@property @synthesize
@interface Person : NSObject{ int myNumber;} @property(nonatomic) int myNumber;//这个关键字是可以带套get 与s ...
- PHP:preg_replace
关于preg_match: http://www.cnblogs.com/helww/p/3466720.html 关于preg_match_all:暂时没有完整的 preg_replace_call ...
- Ubuntu 网管服务器配置
1.设置Linux内核支持ip数据包的转发 echo "1" > /proc/sys/net/ipv4/ip_forward or vi /etc/sysctl.conf ...
- 使用 Eclipse Memory Analyzer 进行简单内存泄漏分析
Java 内存泄露的根本原因: 保存了不可能再被访问的变量类型的引用.因此我们的目的就是要找出这样的引用. 1.测试代码: public class MainActivity extends Acti ...