POJ3090 Visible Lattice Points 欧拉函数
欧拉函数裸题,直接欧拉函数值乘二加一就行了。具体证明略,反正很简单。
题干:
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, y ≤ 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
#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = << ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
int phi[],n;
void init(int n)
{
phi[] = ;
duke(i,,n)
{
phi[i] = i;
}
duke(i,,n)
{
if(phi[i] == i)
{
for(int j = i;j <= n;j += i)
{
phi[j] = phi[j] / i * (i - );
}
}
}
duke(i,,n)
{
phi[i] = phi[i - ] + phi[i];
}
}
int dp[],maxn = ;
int main()
{
read(n);
duke(i,,n)
{
read(dp[i]);
maxn = max(maxn,dp[i]);
}
init(maxn);
duke(i,,n)
{
printf("%d %d %d\n",i,dp[i],phi[dp[i]] * + );
}
return ;
}
代码:
POJ3090 Visible Lattice Points 欧拉函数的更多相关文章
- POJ3090 Visible Lattice Points 欧拉筛
题目大意:给出范围为(0, 0)到(n, n)的整点,你站在原点处,问有多少个整点可见. 线y=x和坐标轴上的点都被(1,0)(0,1)(1,1)挡住了.除这三个钉子外,如果一个点(x,y)不互质,则 ...
- POJ 3090 Visible Lattice Points 欧拉函数
链接:http://poj.org/problem?id=3090 题意:在坐标系中,从横纵坐标 0 ≤ x, y ≤ N中的点中选择点,而且这些点与(0,0)的连点不经过其它的点. 思路:显而易见, ...
- [poj 3090]Visible Lattice Point[欧拉函数]
找出N*N范围内可见格点的个数. 只考虑下半三角形区域,可以从可见格点的生成过程发现如下规律: 若横纵坐标c,r均从0开始标号,则 (c,r)为可见格点 <=>r与c互质 证明: 若r与c ...
- POJ3090 Visible Lattice Points
/* * POJ3090 Visible Lattice Points * 欧拉函数 */ #include<cstdio> using namespace std; int C,N; / ...
- POJ3090 Visible Lattice Points (数论:欧拉函数模板)
题目链接:传送门 思路: 所有gcd(x, y) = 1的数对都满足题意,然后还有(1, 0) 和 (0, 1). #include <iostream> #include <cst ...
- [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< ...
- ACM学习历程—POJ3090 Visible Lattice Points(容斥原理 || 莫比乌斯)
Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal ...
- 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5636 Accepted: ...
- POJ_3090 Visible Lattice Points 【欧拉函数 + 递推】
一.题目 A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), ...
随机推荐
- JAVA学习笔记16——线程的创建和启动
Java使用Thread类代表线程,所有的线程对象都必须是Thread类或其子类的实例.每个线程的作用是完成一定的任务,实际上就是执行一段程序流(一段顺序执行的代码).Java使用线程执行体来代表这段 ...
- telnet mysql3306端口失败
在linux上telnet远程mysql端口失败,经过上网查找后,找到多种方法. (1)我在本地的Navicat上新增了一个用户,主机名是linux的ip,也可以是 %(百分号代表这个用户可以在任何地 ...
- java基础学习日志--String、StringBuffer方法案例
package StringDemo; import java.util.Arrays; /* * 常用String.StringBufer类的方法 */ public class Demo1 { p ...
- Sublime Text 3 快捷键(转载)
本文转自:https://segmentfault.com/a/1190000002570753 (欢迎阅读原文,侵删) Sublime Text 3 快捷键精华版 Ctrl+Shift+P:打开命令 ...
- MyBatis 的基本要素—SQL 映射文件
MyBatis 真正的强大在于映射语句,相对于它强大的功能,SQL 映射文件的配置却是相当简单.对比 SQL 映射配置和 JDBC 代码,发现使用 SQL 映射文件配置可减少 50% 以上的代码,并且 ...
- 创建和获取cookie
创建和获取cookie 制作人:全心全意 cookie:在互联网中,cookie是小段的文本信息,在网络服务器上生成,并发送给浏览器.通过使用cookie可以标识用户身份,记录用户名和密码,跟踪重复用 ...
- PHP上传文件到七牛(Qiniu)
上传文件到七牛最简单的方式就是使用七牛官方最新的SDK 安装PHP SDK composer require qiniu/php-sdk 上传文件到七牛 use Qiniu\Auth; use Qin ...
- 在mac上面运行cherrytree
下载源码包 wget http://www.giuspen.com/software/cherrytree-0.38.4.tar.xz 解压 tar -xvf cherrytree-0.38.4.ta ...
- 【模板】51nod 1006 最长公共子序列Lcs
[题解] dp转移的时候记录一下,然后倒着推出答案即可. #include<cstdio> #include<cstring> #include<algorithm> ...
- spring 学习(二)
public interface BeanPostProcessor { @Nullable default Object postProcessBeforeInitialization(Object ...