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.

Write a program which, given a value for the size, N, computes the number of visible points (x, y) with 0 ≤ x, yN.

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

4
2
4
5
231

Sample Output

1 2 5
2 4 13
3 5 21
4 231 32549 这题目求的是视线所及未挡住的点
因为如(4,2)这样的点,gcd(4,2)=2!=1,有(2,1)将其挡住了。所以这题变向再求下x,y互质的点
可以从斜对角线对半分开,算一半最后乘2即可 代码如下:
 #include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
#define LL long long
#define N 1010
int phi[];
int F[]; void get_phi()
{
memset(phi,,sizeof(phi));
phi[]=;
for(int i=;i<=N;i++)
{
if(!phi[i])
for(int j=i;j<=N;j+=i)
{
if(!phi[j]) phi[j]=j;
phi[j]=phi[j]*(i-)/i;
}
}
} int main()
{
F[]=;
get_phi();
for(int i=;i<=N;i++) F[i]=F[i-]+phi[i];
int n,T;
cin>>T;
for(int i=;i<=T;i++){
cin>>n;
cout<<i<<' '<<n<<' '<<F[n]*+<<endl;
}
return ;
}

POJ 3090 坐标系上的视线遮蔽问题的更多相关文章

  1. POJ 3801 有上下界最小流

    1: /** 2: POJ 3801 有上下界的最小流 3: 4: 1.对supersrc到supersink 求一次最大流,记为f1.(在有源汇的情况下,先使整个网络趋向必须边尽量满足的情况) 5: ...

  2. POJ 3090 Visible Lattice Points 欧拉函数

    链接:http://poj.org/problem?id=3090 题意:在坐标系中,从横纵坐标 0 ≤ x, y ≤ N中的点中选择点,而且这些点与(0,0)的连点不经过其它的点. 思路:显而易见, ...

  3. POJ 3090 Visible Lattice Points (ZOJ 2777)

    http://poj.org/problem?id=3090 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1777 题目大意: ...

  4. POJ 3090 Visible Lattice Points | 其实是欧拉函数

    题目: 给一个n,n的网格,点可以遮挡视线,问从0,0看能看到多少点 题解: 根据对称性,我们可以把网格按y=x为对称轴划分成两半,求一半的就可以了,可以想到的是应该每种斜率只能看到一个点 因为斜率表 ...

  5. poj 3090 &amp;&amp; poj 2478(法雷级数,欧拉函数)

    http://poj.org/problem?id=3090 法雷级数 法雷级数的递推公式非常easy:f[1] = 2; f[i] = f[i-1]+phi[i]. 该题是法雷级数的变形吧,答案是2 ...

  6. 【POJ 3090】 Visible Lattice Points

    [题目链接] http://poj.org/problem?id=3090 [算法] 通过观察发现,在这个平面直角坐标系中,除了(1,1),(1,0)和(0,1),所有可见点的横纵坐标互质 那么,问题 ...

  7. poj 3090 Visible Lattice Points(离线打表)

    这是好久之前做过的题,算是在考察欧拉函数的定义吧. 先把欧拉函数讲好:其实欧拉函数还是有很多解读的.emmm,最基础同时最重要的算是,¢(n)表示范围(1, n-1)中与n互质的数的个数 好了,我把规 ...

  8. [poj 3090]Visible Lattice Point[欧拉函数]

    找出N*N范围内可见格点的个数. 只考虑下半三角形区域,可以从可见格点的生成过程发现如下规律: 若横纵坐标c,r均从0开始标号,则 (c,r)为可见格点 <=>r与c互质 证明: 若r与c ...

  9. [poj] 3090 Visible Lattice Points

    原题 欧拉函数 我们发现,对于每一个斜率来说,这条直线上的点,只有gcd(x,y)=1时可行,所以求欧拉函数的前缀和.2*f[n]+1即为答案. #include<cstdio> #def ...

随机推荐

  1. shutil模块详解2

    1.shutil.make_archive() 实际上是调用了两个模块来实现压缩打包的功能. zipfile和tarfile两个模块,shutil的两个封装的模块. zip是压缩文件,文件内存会变小, ...

  2. Android iconfont字体图标的使用

    1.首先,进入阿里的矢量图标库,在这个图标库里面可以找到很多图片资源,当然了需要登录才能下载或者使用,用GitHub账号或者新浪微博账号登录都可以 2.登录以后,可以搜索自己需要的资源,然后直接下载使 ...

  3. String.format()【示例详解】

    String.format()[示例详解] 整理者:Vashon 前言: String.format 作为文本处理工具,为我们提供强大而丰富的字符串格式化功能,为了不止步于简单调用 String.fo ...

  4. innerHTML的性能问题

    看到一遍文章When innerHTML isn’t Fast Enough,反应了innerHTML在操作量大了以后的性能下降的问题. 并且给出了一个replaceHTML的函数 function  ...

  5. jQuery ajax参数后台获取不到的问题

    <script type="text/javascript"> init(); var alldate = {a : "0",b:"1&q ...

  6. MMRecovery下载和恢复方法教程

    如何能下载到最新版本的恢复软件MMRecovery?下载后我们如何能够快速的使用起来呢?好的,我们接下来就开始这些内容. 一.下载最新版本的恢复软件MMRecovery 1.官方网站下载,如下图在浏览 ...

  7. Matlab 图像转极坐标系

    实心圆环 imgVP1=flip(imgVP1,1);  % 水平翻转 polarVP1=polarVolinPlot(imgVP1); % 调用函数空心圆环 [m,n,~]=size(imgVP2) ...

  8. centos7 搭建jenkins

    centos7 搭建jenkins.note 环境:VMware 虚拟机 centos 7+ jdk 1.8+ tomcat7+jenkins搭建好linux 服务器后,关闭防火墙 停止firewal ...

  9. CAD交互绘制带周长面积的矩形框(网页版)

    主要用到函数说明: _DMxDrawX::DrawLine 绘制一个直线.详细说明如下: 参数 说明 DOUBLE dX1 直线的开始点x坐标 DOUBLE dY1 直线的开始点y坐标 DOUBLE ...

  10. 如何安装多个pip包

    要在命令行上安装多个软件包,只需将它们作为以空格分隔的列表传递,例如: pip install wsgiref boto