poj 3060 Visible Lattice Points

时间:2021-10-21 00:35:27

http://poj.org/problem?id=3090

Visible Lattice Points
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6153   Accepted: 3662

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.

poj 3060 Visible Lattice 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

隐藏很深的一道欧拉函数题,观察下面这个图,将图分成上下两个三角形,观察下三角,横坐标从2开始,发现可以看到的点有(2,1),  (3,1),(3,2),  (4,1),(4,3),  (5,1),(5,2),(5,3),(5,4)

从中可以发先一个规律可以看到的点的横坐标与纵坐标的关系是互质的,由此可以求出下三角横坐标互质的数的和ans,上三角和下三角同理,我们讨论时横坐标是从2开始的,我们忽略了三个点

(0,1),(1,0),(1,1)最后加上即可,最终总个数ans = ans * 2 + 3;

poj 3060 Visible Lattice Points

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm> using namespace std; int solve(int n)
{
int ans = n;
for(int i = ; i * i <= n ; i++)
{
if(n % i == )
{
ans = ans - ans / i;
while(n % i == )
n /= i;
}
}
if(n > )
ans = ans - ans / n;
return ans;
} int main()
{
int t, i, n, x = ;
scanf("%d", &t);
while(t--)
{
x++;
int ans = ;
scanf("%d", &n);
int a = n;
for(i = ; i <= n ; i++)
ans += solve(i);
ans = ans * + ;
printf("%d %d %d\n", x, a, ans);
}
return ;
}

poj 3060 Visible Lattice Points的更多相关文章

  1. 数论 - 欧拉函数的运用 --- poj 3090 &colon; Visible Lattice Points

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

  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&rpar;

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

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

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

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

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

  6. &lbrack;poj&rsqb; 3090 Visible Lattice Points

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

  7. POJ 3090 Visible Lattice Points &vert; 其实是欧拉函数

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

  8. poj 3090 Visible Lattice Points 法利系列&vert;&vert;通过计

    因为图像关于对角线对称.所以我们仅仅看下三角区域. 将x轴看做分母,被圈的点看成分子 依次是{1/2},{1/3,1/2},{1/4,3/4},{1/5,2/5,3/5,4/5} 写成前缀和的形式就是 ...

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

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

随机推荐

  1. WWDC2016-session402-whatsNewInSwift3

    Dock 应用的介绍:1.设计到的东西多2.使用 swift 设计3.Dock 的代码量: 200,000行4.更少的重写相同功能的代码 swift.org 官网介绍 Swift Open Sourc ...

  2. Wildfly8 更改response header中的Server参数

    项目经过局方安全检查需要屏蔽掉服务器中间件信息,查了一下午,网上看到的都是修改jboss7的,我们使用的wildfly8(jboss改名为wildfly),修改地方不一样,折磨了半天. jboss服务 ...

  3. iOS使用技能 - 短信,语言验证码的获取与验证小结

    最近有学习一个小技能,这里小结一下,分享给大家,互相交流. 首先是大体步骤: 在mob官网注册,然后添加短信验证的应用 使用cocoapods导入框架 Podfile文件: platform :ios ...

  4. Windows Server 2012启用Windows功能NetFx3时出错解决方法

    作者:冰点阳光 | 可以转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址:http://baohua.me/operating-system/windows-server-2012- ...

  5. CF739E Gosha is hunting DP&plus;wqs二分

    我是从其他博客里看到这题的,上面说做法是wqs二分套wqs二分?但是我好懒呀,只用了一个wqs二分,于是\(O(nlog^2n)\)→\(O(n^2logn)\) 首先我们有一个\(O(n^3)\)的 ...

  6. CopyOnWriteArrayList&amp&semi;Collections&period;synchronizedList&lpar;&rpar;

    1.ArrayList ArrayList是非线性安全,此类的 iterator() 和 listIterator() 方法返回的迭代器是快速失败的:在创建迭代器之后,除非通过迭代器自身的 remov ...

  7. 自定义Exception——实战篇

    public class EntityConfigurationException : Exception { public EntityConfigurationException(string m ...

  8. BFC&lpar;块级格式化上下文&rpar;

    转载自:https://www.cnblogs.com/asheng2016/p/7281784.html https://blog.csdn.net/jiaojsun/article/details ...

  9. BurpSuite—-Scanner模块&lpar;漏洞扫描&rpar;

    一.简介 Burp Scanner 是一个进行自动发现 web 应用程序的安全漏洞的工具.它是为渗透测试人员设计的,并且它和你现有的手动执行进行的 web 应用程序半自动渗透测试的技术方法很相似. 使 ...

  10. Xuan&period;UWP&period;Framework&lpar;2&rpar;

    上一章主要介绍了Xuan.UWP.Framework.ImageLib的基本用法,这一章具体来看些Xuan.UWP.Framework.ImageLib的使用. 一.首先看下Xuan.UWP.Fram ...