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. 虚方法(virtual)

    虚方法(virtual) Virtual 关键字用于修饰方法.属性.索引器或事件声明,并且允许在派生类中重写这些对象. 看一段代码: using System ; class A { public v ...

  2. mysql多表查询20题

    +-------------------+| Tables_in_dapeng3 |+-------------------+| class || course || s1 || score || s ...

  3. ag-grid-vue的 行默认选中

    that.$nextTick(() => { that.gridListOptions.api.onGroupExpandedOrCollapsed(); that.$nextTick(() = ...

  4. 初学者可能不知道的vue技巧

    前言 大家好,这里是@IT·平头哥联盟,我是首席甩锅官——老金,今天给大家分享的,一些日常中神秘而又简单的vue的实用小技巧,以及我在我司项目中实用vue的总结和坑,跟大家一起分享,希望能给其他攻城狮 ...

  5. iOS 使用UIBezierPath和CAShapeLayer画各种图形

    CAShapeLayer 是 CALayer 的子类,但是比 CALayer 更灵活,可以画出各种图形,当然,你也可以使用其他方式来画,随你. 杂谈 在 CAShapeLayer 中,也可以像 CAL ...

  6. 全文索引Elasticsearch,Solr,Lucene

    最近项目组安排了一个任务,项目中用到了全文搜索,基于全文搜索 Solr,但是该 Solr 搜索云项目不稳定,经常查询不出来数据,需要手动全量同步,而且是其他团队在维护,依赖性太强,导致 Solr 服务 ...

  7. Mybatis和Spring整合&逆向工程

    Mybatis和Spring整合&逆向工程Mybatis和Spring整合mybatis整合Spring的思路目的就是将在SqlMapConfig.xml中的配置移植到Spring的appli ...

  8. oracle的系统表

    -- DBA/ALL/USER/V_$/GV_$/SESSION/INDEX开头的绝大部分都是视图-- DBA_TABLES意为DBA拥有的或可以访问的所有的关系表.-- ALL_TABLES意为某一 ...

  9. 什么是WebSocket (经常听别人讲感觉很高大上其实不然)

    WebSocket 协议在2008年诞生,2011年成为国际标准.现在所有浏览器都已经支持了.WebSocket 的最大特点就是,服务器可以主动向客户端推送信息,客户端也可以主动向服务器发送信息,是真 ...

  10. 洛谷P1035 级数求和

    #include <iostream> using namespace std; int main(){ long k,i; cin >> k; double s=0.0; ; ...