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, ...
随机推荐
- 小飞淙在博客上的第一天——NOIP201505转圈游戏
原本我是在word文档上写这种东西的,在杨老师的“强迫”下,我开始写了博客. 这是我在博客上的第一天,就先来个简单的,下面请看题: 试题描述 有n个小伙伴(编号从0到n-1)围坐一圈玩游戏.按照顺时 ...
- Linux下安装MySQL-5.7
写在前面:此博客是针对MySQL5.7安装教程,其他版本可能略有不同,仅供参考. 第一步:下载mysql 在Linux终端使用wget命令下载网络资源: wget http://mirrors.soh ...
- vhost.sh 源代码,认真看哦
#!/bin/bash # # Web Server Install Script # Created by wdlinux QQ:12571192 # Url:http://www.wdlinux. ...
- Android软件盘InputMethodManager
调用下面代码:(第一次调用显示,再次调用则隐藏,如此反复),this指activity InputMethodManager imm = (InputMethodManager)this.getSys ...
- C语言中的string.h中的内存字符串处理函数
转载请注明出处:http://blog.csdn.net/zhubin215130/article/details/8993403 void *memcpy(void *dest, const voi ...
- /usr 的由来及/usr目录结
/usr 的由来及/usr目录结构 本文转自Delectat.com讨论中,大部分观点认为: usr 是 unix system resources 的缩写: usr 是 user 的缩写: us ...
- Eclipse中配置weka,以及添加算法
Eclipse中配置weka 1 找到weka的安装位置,寻找weka的压缩文件weka-src.jar,将压缩文件解压,解压出的文件夹weka-src. 2 打开Eclipse,新建Java pro ...
- 关于stringWithFormat: - 两段NSString如何合成一段
http://blog.sina.com.cn/s/blog_6b1e4a0601019pib.html str = [NSString stringWithFormat:@"%@,%@&q ...
- mac 命令行读取 u盘
mac 系统命令行读取u盘
- MySQL启动相关知识
使用mysqld和mysqld_safe启动的区别 直接运行mysqld程序来启动MySQL服务的方法很少见,mysqld_safe脚本[注意:mysqld_safe只是一个脚本]会在启动MySQL服 ...