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的更多相关文章

  1. 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points

    Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5636   Accepted: ...

  2. spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演

    SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...

  3. poj 3060 Visible Lattice Points

    http://poj.org/problem?id=3090 Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Tota ...

  4. Spoj 7001 Visible Lattice Points 莫比乌斯,分块

    题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193   Visible Lattice Points Time L ...

  5. 【POJ】3090 Visible Lattice Points(欧拉函数)

    Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7705   Accepted: ...

  6. POJ3090 Visible Lattice Points

    /* * POJ3090 Visible Lattice Points * 欧拉函数 */ #include<cstdio> using namespace std; int C,N; / ...

  7. Visible Lattice Points (莫比乌斯反演)

    Visible Lattice Points 题意 : 从(0,0,0)出发在(N,N,N)范围内有多少条不从重合的直线:我们只要求gcd(x,y,z) = 1; 的点有多少个就可以了: 比如 : 点 ...

  8. 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 ...

  9. SPOJ 7001. Visible Lattice Points (莫比乌斯反演)

    7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0, ...

随机推荐

  1. python实现邮件发送完整代码(带附件发送方式)

    实例一:利用SMTP与EMAIL实现邮件发送,带附件(完整代码) __author__ = 'Administrator'#coding=gb2312 from email.Header import ...

  2. Autofac 组件、服务、自动装配(2)

    一.组件 创建出来的对象需要从组件中来获取,组件的创建有如下4种(延续第一篇的Demo,仅仅变动所贴出的代码)方式: 1.类型创建RegisterType AutoFac能够通过反射检查一个类型,选择 ...

  3. apache: 503

    Any connection over Max, will get a 503 Service Temporarily Unavailable. 503出现的场景:压测url时,发现大量的503错误. ...

  4. mysql -- 备忘

    select distinct(authorid),author from forum_post where tid=1;

  5. iOS 上架提示ipad需要显示四个方位,而我们只能竖屏的时候的解决办法

    勾选requires sull screen

  6. Ubuntu 14.04 Nvidia显卡驱动手动安装及设置

      更换主板修复grub 引导后,无法从Nvidia进入系统(光标闪烁), 可能是显卡驱动出了问题. 1. 进入BIOS设置, 从集成显卡进入系统 将显示器连接到集显的VGI口, 并在BIOS中设置用 ...

  7. PHP之输出控制 ob_start(),ob_get_contents(),ob_end_clean()

    1.常用函数 ob_start();#打开输出缓冲区 ob_get_contents();#获取缓冲区内容 ob_get_length();#获取缓冲区内容长度 ob_clean();#清除之前的所有 ...

  8. Nginx配置IP白名单和黑名单

    白名单设置,访问根目录 location / { allow 123.34.22.155; allow ; deny all; } 黑名单设置,访问根目录 location / { deny 123. ...

  9. Perl 之 use(), require(), do(), %INC and @INC

    来源: http://www.cnblogs.com/itech/archive/2013/03/12/2956185.html 转自:http://perl.apache.org/docs/gene ...

  10. 分页打印控制 摘自于网络:http://www.cnblogs.com/joinger/articles/1807517.html

    代码 style="page-break-after:always;"> 利用CSS控制打印 放在这里,算是一个备份 <style> @media print{ ...