POJ3090:Visible Lattice Points——题解
http://poj.org/problem?id=3090
题目大意:你站在(0,0)的点上看向第一向限的点,点和点会互相阻挡,问最多看到多少点。
很容易想到,我们能看到的点,它的横纵坐标一定是互质的,那么怎么求呢?
首先我们要知道一个东西叫做法雷级数:
#include<cstdio>
#include<cctype>
#include<iostream>
using namespace std;
inline int read(){
int X=,w=; char ch=;
while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
while(isdigit(ch)) X=(X<<)+(X<<)+(ch^),ch=getchar();
return w?-X:X;
}
int f[],e[];
bool h[];
int p[],cnt=;
void Euler(int n){
e[]=;
for(int i=;i<=n;i++){
if(!h[i]){
cnt++;
p[cnt]=i;
e[i]=i-;
}
for(int j=;j<=cnt&&i*p[j]<=n;j++){
h[i*p[j]]=;
if(i%p[j]==){
e[i*p[j]]=e[i]*p[j];
break;
}
e[i*p[j]]=e[i]*(p[j]-);
}
}
return;
}
void Farley(int n){
f[]=;
for(int i=;i<=n;i++){
f[i]=f[i-]+e[i];
}
return;
}
int main(){
Euler();
Farley();
int c=read();
for(int i=;i<=c;i++){
int n=read();
printf("%d %d %d\n",i,n,f[n]*-);
}
return ;
}
POJ3090:Visible Lattice Points——题解的更多相关文章
- POJ3090 Visible Lattice Points
/* * POJ3090 Visible Lattice Points * 欧拉函数 */ #include<cstdio> using namespace std; int C,N; / ...
- ACM学习历程—POJ3090 Visible Lattice Points(容斥原理 || 莫比乌斯)
Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal ...
- POJ3090 Visible Lattice Points 欧拉函数
欧拉函数裸题,直接欧拉函数值乘二加一就行了.具体证明略,反正很简单. 题干: Description A lattice point (x, y) in the first quadrant (x a ...
- 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< ...
- POJ3090 Visible Lattice Points 欧拉筛
题目大意:给出范围为(0, 0)到(n, n)的整点,你站在原点处,问有多少个整点可见. 线y=x和坐标轴上的点都被(1,0)(0,1)(1,1)挡住了.除这三个钉子外,如果一个点(x,y)不互质,则 ...
- Spoj 7001 Visible Lattice Points 莫比乌斯,分块
题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193 Visible Lattice Points Time L ...
- 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5636 Accepted: ...
- spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演
SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...
随机推荐
- datawindow自动换行打印,需结合该函数一起使用
1.设置 具体步骤如下: 1) 在DataWindow Painter中打开此DataWindow对象. 2) 在需设定自动折行的列上双击鼠标, 弹开此列的属性窗口. 3) 选择P ...
- 「日常训练&知识学习」树的分块(王室联邦,HYSBZ-1086)
题意与分析 这题的题意就是树分块,更具体的看题目(中文题). 学习这一题是为了树的分块,为树上莫队做铺垫. 参考1:https://blog.csdn.net/LJH_KOQI/article/det ...
- 分享一个 UiPath Studio 相关的公众号
RPA 和 UiPath 方面的资料比较少,因此我们自己创建了一个公众号,专门用于传播 UiPath 相关的知识. 会定期发布 UiPath 学习相关的信息.是目前难得的 UiPath 中文资源. 公 ...
- Qt-第一个QML程序-3-自定义一个按钮
项目基本信息前两个已经说了,这里直接放下运行截图, 对的,这里就是说上面的那个红色的按钮,这里需要了解Qml的动画和状态 这里先把整个按钮的代码写出来,一点一点写 Rectangle { id:clo ...
- 【progress】 进度条组件说明
progress 进度条组件 原型: <progress percent="[Float(0-100)]" show-info="[Boolean]" b ...
- 软件工程第四周作业之四则运算-C#实现
拿到题目的时候,快放假了,也没心思做.十月七号的一下午大概从两点做到八点半,加上十月八号的十二点半到两点半,做了一共八个半小时,去掉吃饭半个小时那么一共做了八个小时. 逆波兰表达式我是扒的别人代码,没 ...
- Word Ladder Problem (DFS + BFS)
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest t ...
- lintcode-191-乘积最大子序列
191-乘积最大子序列 找出一个序列中乘积最大的连续子序列(至少包含一个数). 样例 比如, 序列 [2,3,-2,4] 中乘积最大的子序列为 [2,3] ,其乘积为6. 标签 子数组 领英 动态规划 ...
- iOS-tableView刷新指定行,组
/一个section刷新 NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:]; [tableview reloadSections:inde ...
- idea dubbo jar error:cvc-complex-type.2.4.c: 通配符的匹配很全面, 但无法找到元素 'dubbo:application' 的声明
声明: 出现这个错误的情形是,在idea开发环境里面运行是没有问题的,使用哦idea自带的打包工具生成jar之后,运行jar的时候报的这个错误,如果不是这个情况,这篇文章可能不适用. 主要的原因是sp ...