Visible Lattice Points
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7094   Accepted: 4288

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

Source

 
#include<cstdio>
using namespace std;
const int N=;
int T,n,tot,phi[N],prime[N/];
bool check[N];
void prepare(){
phi[]=;n=;
for(int i=;i<=n;i++){
if(!check[i]) prime[++tot]=i,phi[i]=i-;
for(int j=;j<=tot&&i*prime[j]<=n;j++){
check[i*prime[j]]=;
if(!(i%prime[j])){phi[i*prime[j]]=phi[i]*prime[j];break;}
else phi[i*prime[j]]=phi[i]*(prime[j]-);
}
}
}
int main(){
prepare();
scanf("%d",&T);
for(int i=;i<=T;i++){
scanf("%d",&n);
int ans=;
for(int j=;j<=n;j++) ans+=phi[j];
ans<<=;ans|=;
printf("%d %d %d\n",i,n,ans);
}
return ;
}
 

POJ3090的更多相关文章

  1. POJ3090 Visible Lattice Points

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

  2. POJ3090 巧用欧拉函数 phi(x)

    POJ3090 给定一个坐标系范围 求不同的整数方向个数 分析: 除了三个特殊方向(y轴方向 x轴方向 (1,1)方向)其他方向的最小向量表示(x,y)必然互质 所以对欧拉函数前N项求和 乘2(关于( ...

  3. poj3090欧拉函数求和

    E - (例题)欧拉函数求和 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     ...

  4. 【POJ3090】Visible Lattice Points

    题目大意:求 \[\sum\limits_{i=2}^n\phi(i)\] 题解:利用与埃筛类似的操作,可在 \(O(nlogn)\) 时间求出结果. 代码如下 #include <cstdio ...

  5. 欧拉函数,打表求欧拉函数poj3090

    欧拉函数 φ(n) 定义:[1,N]中与N互质的数的个数 //互质与欧拉函数 /* 求欧拉函数 按欧拉函数计算公式,只要分解质因数即可 */ int phi(int n){ int ans=n; ;i ...

  6. POJ3090 Visible Lattice Points (数论:欧拉函数模板)

    题目链接:传送门 思路: 所有gcd(x, y) = 1的数对都满足题意,然后还有(1, 0) 和 (0, 1). #include <iostream> #include <cst ...

  7. POJ3090(SummerTrainingDay04-M 欧拉函数)

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

  8. [POJ3090]Visible Lattice Points(欧拉函数)

    答案为3+2*∑φ(i),(i=2 to n) Code #include <cstdio> int T,n,A[1010]; void Init(){ for(int i=2;i< ...

  9. POJ3090:Visible Lattice Points——题解

    http://poj.org/problem?id=3090 题目大意:你站在(0,0)的点上看向第一向限的点,点和点会互相阻挡,问最多看到多少点. 很容易想到,我们能看到的点,它的横纵坐标一定是互质 ...

随机推荐

  1. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-人机界面如何让文本框可以输入,文本框可以编辑

    选中一个文本框,然后在属性中双击输入配置的OnMouseDown事件(也可以是别的事件,但都是通过这种方法)   在左侧点击写变量,然后输入类型改成VisuDialos.Numpad(数字键盘方式), ...

  2. vue - 认识ora

    主要用来实现node.js命令行环境的loading效果,和显示各种状态的图标等... const ora = require('ora'); const spinner = ora('Loading ...

  3. Excel中如何将时间戳转为时间?

    Unix时间戳转换Excel时间? Excel中如何将时间戳转为时间? Excel默认不支持Unix格式时间戳,这在导入数据时十分不便.可以用以下公式将时间戳转换成Excel格式的时间: =(x+8* ...

  4. 【VBA编程】15.WorkSheet对象常用属性

    [Cells属性] Cells属性用于返回一个Range对象,表示工作表中所有的单元格,包括已经使用的单元格和未使用的单元格. [代码区域] Sub 使用Cells属性() '声明变量 Dim wk ...

  5. bye 2013 hello 2014

    最近两个月除了必要的工作外,其余时间都在干一些我其实平时很少干的事, 喝酒.唱歌.打麻将.玩牌.以及到处跑找朋友玩,也许是过年的原因我放纵了自己,也许是自己心中的烦恼.我的博客记录着我每次看书学习的笔 ...

  6. strults2标签s:set的用法

    struts2标签<s:set></s:set>的用法.原理 http://liuna718-163-com.iteye.com/blog/1124654     我的例子: ...

  7. TCP/IP --概述

    分层 网络协议通常分不同层次进行开发,每一层分别负责不同的通信功能.一个协议族,比如T C P / I P,是一组不同层次上的多个协议的组合.T C P / I P通常被认为是一个四层协议系统.,如图 ...

  8. nginx 404重定向到自定义页面

    在访问时遇到上面这样的404错误页面,我想99%(未经调查,估计数据)的用户会把页面关掉,用户就这样悄悄的流失了.如果此时能有一个漂亮的页面能够引导用户去他想去的地方必然可以留住用户.因此,每一个网站 ...

  9. FZU2171:防守阵地 II(线段树)

     Problem Description 部队中总共同拥有N个士兵,每一个士兵有各自的能力指数Xi.在一次演练中,指挥部确定了M个须要防守的地点,指挥部将选择M个士兵依次进入指定地点进行防守任务.获得 ...

  10. ISA2006安装和部署基础(虚拟机非域环境)

    0x00. 为了測试基于HTTP隧道的绕过ISA,必须搭建模拟环境,为了不麻烦,我们这里不配合域环境认证.本次实验利用Vmware 10.0搭建好开发环境,实现ISA2006安装和部署,同一时候设定基 ...