Visible Lattice Points
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8397   Accepted: 5144

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

[Submit]   [Go Back]   [Status]   [Discuss]

刚开始脑子简单去暴力循环。。当然是T掉啦!

原来一直不明白欧拉函数,f(n)代表小于n的正整数中与n互质的数的数目。。就是这个题嘛。。记住了。

 #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include<iostream>
#include <cmath>
#include<string>
#define ll long long
#define dscan(a) scanf("%d",&a)
#define mem(a,b) memset(a,b,sizeof a)
using namespace std;
#define MAXL 1105
#define maxn 1000005
int f[MAXL];
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>'') {if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<='') {x=*x+ch-'';ch=getchar();}
return x*f;
}
int p[MAXL], pNum, phi[MAXL];
void ola()
{
int i, j;
for(i = ; i < MAXL; i++) {
if(!f[i]) { p[pNum++] = i; phi[i] = i-;}
for(j = ; j < pNum && p[j] * i < MAXL; j++ ) {
f[p[j]*i] = ;
if(i % p[j] == ){
phi[i*p[j]] = phi[i] * p[j];
break;
}
else phi[i*p[j]] = phi[i] *(p[j] - );
}
}
}
int main()
{
int n,c;
cin>>n;int hh=;
ola();
while(n--)
{
int c=read();
phi[]=;
cout<<hh++<<" "<<c<<" ";
ll ans=;
for(int i=;i<=c;++i) ans+=phi[i];
cout<<ans*+<<endl;
}
}

POJ 3090的更多相关文章

  1. POJ 3090 Visible Lattice Points 欧拉函数

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

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

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

  3. 【POJ 3090】 Visible Lattice Points

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

  4. POJ 3090 Visible Lattice Points (ZOJ 2777)

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

  5. 【poj 3090】Visible Lattice Points(数论--欧拉函数 找规律求前缀和)

    题意:问从(0,0)到(x,y)(0≤x, y≤N)的线段没有与其他整数点相交的点数. 解法:只有 gcd(x,y)=1 时才满足条件,问 N 以前所有的合法点的和,就发现和上一题-- [poj 24 ...

  6. 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points

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

  7. POJ 3090 (欧拉函数) Visible Lattice Points

    题意: UVa 10820 这两个题是同一道题目,只是公式有点区别. 给出范围为(0, 0)到(n, n)的整点,你站在原点处,问有多少个整点可见. 对于点(x, y), 若g = gcd(x, y) ...

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

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

  9. POJ 3090 Visible Lattice Points 【欧拉函数】

    <题目链接> 题目大意: 给出范围为(0, 0)到(n, n)的整点,你站在(0,0)处,问能够看见几个点. 解题分析:很明显,因为 N (1 ≤ N ≤ 1000) ,所以无论 N 为多 ...

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

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

随机推荐

  1. 51nod——2487小b和环

    dp[ i ][ 0 ] : 第i个位置不取 dp[ i ][ 1 ] : 第i个位置取 这样就可以得到状态转移方程: dp[i][0]=max(max(dp[i][0],dp[i-1][1]),dp ...

  2. PAT 乙级 1024

    题目 题目地址:PAT 乙级 1024 题解 模拟题,重点需要考虑到各种不同情况:简单来说一下: 因为输入格式固定,所以把不同的部分分别存储和处理可以在很大程度上简化运算:其中需要考虑最多的就是小数部 ...

  3. 使用jieba和wordcloud进行中文分词并生成《悲伤逆流成河》词云

    因为词云有利于体现文本信息,所以我就将那天无聊时爬取的<悲伤逆流成河>的评论处理了一下,生成了词云. 关于爬取影评的爬虫大概长这个样子(实际上是没有爬完的): #!/usr/bin/env ...

  4. JAVA运行环境配置

    win10下,右击我的电脑-->高级系统设置-->高级-->环境变量-->系统变量 1新建 变量名   JAVA_HOME 变量值   C:\Program Files\Jav ...

  5. DAG上的动态规划——嵌套矩阵问题

    问题描述:有n个矩形,每个矩形可以用两个整数a,b描述,表示它的长和宽.矩形X(a,b)可以嵌套在矩形Y(c,d)中当且仅当a<c,b<d,或者b<c,a<d(相当于把矩形X旋 ...

  6. [BZOJ1503]郁闷的出纳员(Splay)

    Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经常 ...

  7. mysql-不恰当的update语句使用主键和索引导致mysql死锁

    背景知识:MySQL有三种锁的级别:页级.表级.行级. MyISAM和MEMORY存储引擎采用的是表级锁(table-level locking):BDB存储引擎采用的是页面锁(page-level ...

  8. Redis实现之链表

    链表 链表提供了高效的节点重排能力,以及顺序性的节点访问顺序,并且可以通过增删节点来灵活地调整链表的长度.作为一种常用数据结构,链表内置在很多高级的编程语言里面,因为Redis使用的C语言并没有内置这 ...

  9. 《Scrum实战》第4次课【全职的Scrum Master】作业汇总

    1组: 孟帅 http://www.cnblogs.com/mengshuai1982/p/7375008.html 3组: 张亚辉 http://www.jianshu.com/p/df9eee08 ...

  10. php 判断一个点是否在一个多边形区域内

    <?php class pointMap{ private static $coordArray; private static $vertx = []; private static $ver ...