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. Oozie的架构

    Oozie的架构图,如下: 从oozie的架构图中,可以看到所有的任务都是通过oozie生成相应的任务客户端,并通过任务客户端来提交相应的任务. 继续...

  2. iOS之tableView性能优化/tableView滑动卡顿?

    本文围绕以下几点展开tableView性能优化的论述? 1.UITableViewCell重用机制? 2.tableView滑动为什么会卡顿? 3.优化方法? 4.总结 1.UITableViewCe ...

  3. AJPFX浅谈Java新手问题之缺少良好的编程习惯

    ★随意地命名 有些新手写程序,当需要定义某个变量名(也可能是函数名.类名.包名等)时,随意地一敲键盘,名字就起好了......若干星期后,碰到某 bug,再来看自己写的代码时,心中暗自嘀咕:“这代码是 ...

  4. canvas画笑脸

    <style> body {   background: black;   text-align: center; } #cans {   background: white; } < ...

  5. obj.style 和currentstyle 等区别

    版权声明:本文为博主原创文章,未经博主允许不得转载. 获取样式  obj.style   和currentstyle  等区别   obj.style只能获得内嵌样式(inline Style)就是写 ...

  6. Android 基础知识总结

    搞了这么久安卓开发,对基础的知识点总会遗忘,所有有必要总结一下:

  7. Sublime折腾记录

    本文可以理解为FAQ,主要是为了大家GET一些技能,具体内容包括LICENSE.重置.Package Control的安装,其他内容以后可能补充... 最后说明一下自己的版本:Build 3114 L ...

  8. Android CursorAdapter的使用

    CursorAdapter继承于BaseAdapter,为Cursor和ListView连接提供了桥梁. 首先看一下CursorAdapter的部分源码: /** * @see android.wid ...

  9. gitlab利用ssh方式拉取代码

    问题1: Bad owner or permissions on .ssh/config的解决 当为本机配一个固定用户名远程登录某主机时,配置了一个config文件,但是在执行ssh免密码登录时报如下 ...

  10. 谷歌 滚动条样式 scrollbar

    谷歌  滚动条样式 scrollbar main.less :: 是css3 最新的伪类 /*滚动条整体样式*/ ::-webkit-scrollbar { width: 10px; height: ...