Visible Lattice Points
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7705   Accepted: 4707

Description

A lattice point (xy) 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 (xy) 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 (xy) with 0 ≤ xy ≤ 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 (xy) with 0 ≤ xy ≤ N.

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
----------------------------------------------------------------- 分析:和[SDOI2008]仪仗队没有什么区别,只是加了个多数据。
[SDOI2008]仪仗队 -》 http://www.cnblogs.com/noblex/p/7535245.html
还是放一下代码吧
 #include <cstdio>
#include <cmath>
const int maxn=;
int phi[maxn];
int phis(int n)
{
for(int i=;i<=n;i++) phi[i]=;
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-);
}
}
return ;
}
int main()
{
int t,n;
scanf("%d",&t);
phis(maxn);
for(int i=;i<=t;i++)
{
long long sum=;
scanf("%d",&n);
for(int j=;j<=n;j++) sum+=phi[j];
sum*=;sum+=;
printf("%d %d %lld\n",i,n,sum);
}
return ;
}
 

【POJ】3090 Visible Lattice Points(欧拉函数)的更多相关文章

  1. POJ 3090 Visible Lattice Points 欧拉函数

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

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

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

  3. POJ3090 Visible Lattice Points 欧拉函数

    欧拉函数裸题,直接欧拉函数值乘二加一就行了.具体证明略,反正很简单. 题干: Description A lattice point (x, y) in the first quadrant (x a ...

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

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

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

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

  6. POJ 3090 Visible Lattice Points | 其实是欧拉函数

    题目: 给一个n,n的网格,点可以遮挡视线,问从0,0看能看到多少点 题解: 根据对称性,我们可以把网格按y=x为对称轴划分成两半,求一半的就可以了,可以想到的是应该每种斜率只能看到一个点 因为斜率表 ...

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

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

  8. [poj] 3090 Visible Lattice Points

    原题 欧拉函数 我们发现,对于每一个斜率来说,这条直线上的点,只有gcd(x,y)=1时可行,所以求欧拉函数的前缀和.2*f[n]+1即为答案. #include<cstdio> #def ...

  9. POJ3090 Visible Lattice Points 欧拉筛

    题目大意:给出范围为(0, 0)到(n, n)的整点,你站在原点处,问有多少个整点可见. 线y=x和坐标轴上的点都被(1,0)(0,1)(1,1)挡住了.除这三个钉子外,如果一个点(x,y)不互质,则 ...

  10. POJ 3090 Visible Lattice Points (ZOJ 2777)

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

随机推荐

  1. ctf常见php弱类型分析

    1. 布尔反序列化 $unserialize_str = $_POST['password']; $data_unserialize = unserialize($unserialize_str); ...

  2. docfx (一)

    什么是docFX? DocFX 是一个基于.NET的API文档生成器,当前支持 C# 和 VB.它可以通过你的代码中的三斜杠注释生成 API 参考文档.同样也支持你使用 Markdown 文件创建一些 ...

  3. SVG图案

    前面的话 给SVG元素应用填充和描边,除了使用纯色和渐变外,还可以使用图案.本文将详细介绍SVG图案 概述 <pattern>可以实现重复的效果,在canvas中被翻译为模式,而在SVG中 ...

  4. chrome开发工具指南(十)

    检查和删除 Cookie 从 Application 面板检查和删除 Cookie. TL;DR 查看与 Cookie 有关的详细信息,例如名称.值.网域和大小,等等. 删除单个 Cookie.选定网 ...

  5. ios 初体验<真机调试>

    1.很多小伙伴,初学ios后面,都想迫不及待的连接上真机,在真机上调试,本人今天花了许久时间,在网上查了许多资料,一直出现了个问题导致我没法真机调试, 问题一:Your session has exp ...

  6. CGI + FastCGI(PHP-FPM)联系和区别的图解 + 注释

    一.背景 参考了几篇文章,总结成图解 + 注释方便以后查阅. 参考资料: 1.https://www.zhihu.com/question/19582041 2.https://segmentfaul ...

  7. About Cheating and Plagiarism

    我先描述一下此次事件的具体经过.昨天3月15号的晚上十点,是第四次作业的deadline.在15号之前,只有五位同学提交了作业,而在临近deadline的这几个小时内密密麻麻地提交了二十多份作业.和第 ...

  8. 如何设置Cookie 的值为中文的内容

    默认情况下,cookie的值是不允许中文内容的.可以借助于java.net.URLEncoder先对中文字符串进行编码,将编码后的结果设为cookie值.当程序要读取cookie值时,先读取,然后使用 ...

  9. 201521123112《Java程序设计》第8周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 在做PTA5.3的时候一段看起来比较复杂的代码: List<En ...

  10. 201521123003《Java程序设计》第3周学习总结

    1. 本章学习总结 你对于本章知识的学习总结 了解和学会使用更多已有的类,如Calendar类.Math类.Arrays类等等 public.private的权限修饰 学会使用在Eclipse工具栏中 ...