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. hibernate学习系列-----(8)hibernate对集合属性的操作之Collectioon集合篇

    度过短暂的周末,又到了周一,继续轻松而愉快的学习,紧承以前的学习,继续了解hibernate对集合的操作学习之旅! 在上一篇中,就已经提前说过,这一篇的内容以及下一篇的内容会有很多相似之处,这里就不再 ...

  2. lodash kebabCase

    _.kebabCase([string='']) 转换字符串为 kebab case. _.kebabCase('Foo Bar'); // => 'foo-bar' _.kebabCase(' ...

  3. 基于MaterialDesign设计风格的妹纸app的简单实现

    代码地址如下:http://www.demodashi.com/demo/11644.html *今天看了郭神的第二行代码,深深的被MaterialDesign的设计风格所吸引,然后就照例做了一个小D ...

  4. WP8 NavigationInTransition实现页面切换效果

    NavigationInTransition这个是实现页面切换效果,而且没控件来拖,要自己手动写, 将App.xaml.cs中InitializePhoneApplication()函数里的RootF ...

  5. iOS开发-XCode常用快捷键整理

    前言:如果我们能够掌握并巧妙地使用快捷键,可以大大加快我们的工作效率,这个对经常使用快捷键的人们来说,应该很容易理解.因此我们需要做的是,针对于自己经常使用的快捷键去进行记忆.我不会推荐你们去把所有的 ...

  6. MYSQL版查询分页存储过程

    /*--名称:MYSQL版查询分页存储过程 --输入参数:@fields -- 要查询的字段用逗号隔开--输入参数:@tables -- 要查询的表--输入参数:@where -- 查询条件--输入参 ...

  7. ORM进阶之Hibernate 的三大对象

    ORM进阶之 ORM简单介绍 ORM进阶之Hibernate 简单介绍及框架搭 ORM进阶之Hibernate 的三大对象 我们在上一篇博客中讲到了怎样搭建一个Hibernate框架, 提到Hiber ...

  8. 转 spring官方文档中文版

    转 http://blog.csdn.net/tangtong1/article/details/51326887另附码云地址 https://gitee.com/free/spring-framew ...

  9. Google I/O 2014 大会总结 Android开发新方向

    昨天晚上,Google I/O 2014大会召开,会上主要展示了下面几个部分的创新内容: Android L 操作系统 首先是界面,谷歌又一次设计了一套 UI 规范.并称之为"Materia ...

  10. RabbitMQ基础概念

    转至:http://blog.csdn.net/whycold/article/details/41119807 RabbitMQ简介 AMQP,即Advanced Message Queuing P ...