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

题目大意:你站在(0,0)的点上看向第一向限的点,点和点会互相阻挡,问最多看到多少点。

很容易想到,我们能看到的点,它的横纵坐标一定是互质的,那么怎么求呢?

首先我们要知道一个东西叫做法雷级数:

F1:0/1 1/1
F2:0/1 1/2 1/1
F3:0/1 1/3 1/2 2/3 1/1
F4:0/1 1/4 1/3 1/2 2/3 3/4 1/1
F5:0/1 1/5 1/4 1/3 2/5 1/2 3/5 2/3 3/4 4/5 1/1
F6:0/1 1/6 1/5 1/4 1/3 2/5 1/2 3/5 2/3 3/4 4/5 5/6 1/1
……
我们发现新加进来的数,它的分母为n,分子与n互质,所以加入了与n互质的数的个数。
是不是欧拉函数啊(叫做E)
所以Fn=Fn-1+En
但是我们知道我们要求的F可以分子分母相反,那么实际我们求的是Fn*2-1(-1因为1/1)
#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——题解的更多相关文章

  1. POJ3090 Visible Lattice Points

    /* * POJ3090 Visible Lattice Points * 欧拉函数 */ #include<cstdio> using namespace std; int C,N; / ...

  2. ACM学习历程—POJ3090 Visible Lattice Points(容斥原理 || 莫比乌斯)

    Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal ...

  3. POJ3090 Visible Lattice Points 欧拉函数

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

  4. POJ3090 Visible Lattice Points (数论:欧拉函数模板)

    题目链接:传送门 思路: 所有gcd(x, y) = 1的数对都满足题意,然后还有(1, 0) 和 (0, 1). #include <iostream> #include <cst ...

  5. [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< ...

  6. POJ3090 Visible Lattice Points 欧拉筛

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

  7. Spoj 7001 Visible Lattice Points 莫比乌斯,分块

    题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193   Visible Lattice Points Time L ...

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

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

  9. spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演

    SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...

随机推荐

  1. Hadoop3.0新特性

    1. Hadoop3.0简介 Hadoop 2.0是基于JDK 1.7开发的,而JDK 1.7在2015年4月已停止更新,这直接迫使Hadoop社区基于JDK1.8重新发布一个新的Hadoop版本,而 ...

  2. 微信小程序如何性能测试?

    背景: 微信小程序作为手机页面的一种,相比传统的网站和应用来说存在比较特殊的地方: 1.  开发者往往对程序做了限制,只能通过微信客户端访问 2.  通过微信的Oauth进行认证 这样往往会导致我们的 ...

  3. katalon系列七:Katalon Studio全局变量

    假如你有3个脚本都用到了用户名,如果是写死在脚本中,那么需要改变的时候,你需要修改3个地方,我们可以把用户名设为全局变量,在3个脚本中引用,需要修改时只要修改全局变量中的用户名值即可. 在Katalo ...

  4. C指针函数中的局部变量返回

    所谓指针函数其实就是  :一个函数的返回值为指针. 指针函数定义:返回类型标识符*  函数名(形参列表){函数体} eg:   int*  fun1(int n){} 指针函数和局部变量返回解析: 简 ...

  5. New Year and Domino:二维前缀和

    题目描述: They say "years are like dominoes, tumbling one after the other". But would a year f ...

  6. POJ 2177 Ghost Busters(三维几何)

    Description The famous Ghost Busters team has decided to upgrade their Ectomobile (aka Ecto-1) with ...

  7. Java 集合框架之Collection

    此图是 java 中 Collection 相关的接口与类的关系的类图.其中,类只是集合框架的一部分,比较常用的一部分. 第一次画类图,着实很费劲,不过收获也不小. 下面是相关接口和类的解释说明.文字 ...

  8. Calculator PartⅢ

    GitHub/object-oriented The title of the work 这次敲代码耗时相对较短,但是始终无法完成debug步骤,目前上传的代码可以通过编译,但运行即报停,问题调试为内 ...

  9. Tiny4412 LED 程序

    package cn.hyc.led; import android.os.Bundle; import android.app.Activity; import android.view.Menu; ...

  10. AngularJS 学习笔记--01

    学习 AngularJS 要先了解 MVC 模式 , 即 " 模型--视图--控制器 " . 模型: 包含了需要用到的数据 ; 有两种广义上的模型 : 视图模型 , 只表示从控制器 ...