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), ...
随机推荐
- ES 提案的各状态
JavaScrpit,亦即 ECMAScript,新功能的演进是由一个叫 TC39 这么个组织在统筹协调和推进的. 一般新特性会由社区先提案,被采纳后开始进入下一流程.一个提案到最终落地到成为标准,需 ...
- 07C语言程序语句
C语言程序语句 判断语句 if(表达式) {语句} #include <stdio.h> int main(){ printf("请输入2个数字:"); int a,b ...
- spark学习(1)---dataframe操作大全
一.dataframe操作大全 https://blog.csdn.net/dabokele/article/details/52802150 https://www.jianshu.com/p/00 ...
- Laravel5.5 综合使用
使用 Laravel5.5 开发一个自动交割的项目,把使用到的开源扩展包及特性整理起来,以供后续使用. 一.安装IDE提示工具 Laravel IDE Helper 是一个极其好用的代码提示及补全工具 ...
- vue中axios设置
//设置默认全局baseURL axios.defaults.baseURL=process.env.BASE_API; //设置默认全局携带浏览器cookie axios.defaults.with ...
- __repr__()
class A : def __init__(self,name): self.name=name #def __str__(self): # return '**%s**'%self.name de ...
- Maven学习总结(30)——Maven项目通用三级版本号说明
项目版本号说明 当前版本号:1.0.0-SNAPSHOT 本项目采用通用的三级版本号,版本号格式是[主版本号].[副版本号].[修复版本号]-[稳定状态],如:1.0.0-SNAPS ...
- [bzoj1072][SCOI2007]排列(状态压缩DP)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1072 分析:看了题解才知道,状态的设计很巧妙,用余数表示,即f[i][j]表示二进制状 ...
- Java使用JNative调用DLL库
编写测试DLL文件,源文件参照JNA调用用的DLL文件.地址:http://www.cnblogs.com/vevy/p/9076941.html (很重要)右键项目 --> 属性 --> ...
- spring项目启动需要的几个注解
1.@ComponentScan注解,spring context包下,可以理解嘛,扫描srping bean放在ioc容器中的. ApplicationContext是接口,就是IOC容器嘛,也在这 ...