题意:

UVa 10820

这两个题是同一道题目,只是公式有点区别。

给出范围为(0, 0)到(n, n)的整点,你站在原点处,问有多少个整点可见。

对于点(x, y), 若g = gcd(x, y) > 1,则该点必被点(x/g, y/g)所挡住。

因此所见点除了(1, 0)和(0, 1)满足横纵坐标互素。

最终答案为,其中的+3对应(1, 1) (1, 0) (0, 1)三个点

 #include <cstdio>

 const int maxn = ;
int phi[maxn + ]; void get_table()
{
for(int i = ; i <= maxn; ++i) if(!phi[i])
{
for(int j = i; j <= maxn; j += i)
{
if(!phi[j]) phi[j] = j;
phi[j] = phi[j] / i * (i - );
}
}
} int main()
{
freopen("3090in.txt", "r", stdin); get_table();
for(int i = ; i <= maxn; ++i) phi[i] += phi[i - ]; int T;
scanf("%d", &T);
for(int kase = ; kase <= T; ++kase)
{
int n;
scanf("%d", &n);
printf("%d %d %d\n", kase, n, phi[n]*+);
} return ;
}

代码君

POJ 3090 (欧拉函数) Visible Lattice Points的更多相关文章

  1. POJ 3090 欧拉函数

    求一个平面内可见的点,其实就是坐标互质即可,很容易看出来或者证明 所以求对应的欧拉函数即可 #include <iostream> #include <cstdio> #inc ...

  2. POJ 2407 (欧拉函数)

    题目链接: http://poj.org/problem?id=2407 题目大意:求小于n且与n互质的正整数个数. 解题思路: 欧拉函数=小于n且与n互质的正整数个数. 公式=n*(1-1/P1)* ...

  3. poj 2407 欧拉函数裸题

    http://poj.org/problem?id=2407 题意:多组数据,每次输入一个数 ,求这个数的欧拉函数 int euler_phi(int n){//单个欧拉函数 int m=(int)s ...

  4. POJ 2478 欧拉函数打表的运用

    http://poj.org/problem?id=2478 此题只是用简单的欧拉函数求每一个数的互质数的值会超时,因为要求很多数据的欧拉函数值,所以选用欧拉函数打表法. PS:因为最后得到的结果会很 ...

  5. Relatives POJ - 2407 欧拉函数

    题意: 给你一个正整数n,问你在区间[1,n)中有多少数与n互质 题解: 1既不是合数也不是质数(1不是素数) 互质是公约数只有1的两个整数,叫做互质整数.公约数只有1的两个自然数,叫做互质自然数 所 ...

  6. 找新朋友 HDU - 1286 欧拉函数模板题

    题意: 求出来区间[1,n]内与n互质的数的数量 题解: 典型的欧拉函数应用,具体见这里:Relatives POJ - 2407 欧拉函数 代码: 1 #include<stdio.h> ...

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

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

  8. 【poj 3090】Visible Lattice Points(数论--欧拉函数 找规律求前缀和)

    题意:问从(0,0)到(x,y)(0≤x, y≤N)的线段没有与其他整数点相交的点数. 解法:只有 gcd(x,y)=1 时才满足条件,问 N 以前所有的合法点的和,就发现和上一题-- [poj 24 ...

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

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

随机推荐

  1. Handlebars模板引擎中的each嵌套及源码浅读

    若显示效果不佳,可移步到愚安的小窝 Handlebars模板引擎作为时下最流行的模板引擎之一,已然在开发中为我们提供了无数便利.作为一款无语义的模板引擎,Handlebars只提供极少的helper函 ...

  2. Careercup - Google面试题 - 4716965625069568

    2014-05-06 00:17 题目链接 原题: Given a -D matrix represents the room, obstacle and guard like the followi ...

  3. shell 学习基地

    http://blog.csdn.net/column/details/shell-daily-study.html?&page=2

  4. 【转载】Spring中的applicationContext.xml与SpringMVC的xxx-servlet.xml的区别

    一直搞不明白两者的区别. 如果使用了SpringMVC,事实上,bean的配置完全可以在xxx-servlet.xml中进行配置.为什么需要applicationContext.xml?一定必须? 一 ...

  5. IntelliJ IDEA 14 创建maven项目二

    前言: 在我的idea14使用maven创建web工程文章介绍了如何运用idea14创建maven项目--但有瑕疵,如下: 今天在群里交流才得知起因: 原来一直这样创建的--但结果都一样,均出现上面的 ...

  6. Hibernate各种主键生成策略与配置详解【附1--<generator class="foreign">】

    1.assigned 主键由外部程序负责生成,在 save() 之前必须指定一个.Hibernate不负责维护主键生成.与Hibernate和底层数据库都无关,可以跨数据库.在存储对象前,必须要使用主 ...

  7. Spring3+hibernate4+struts2整合的 过程中发生如下错误

    严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis ...

  8. Sandcastle:生成.NET API文档的工具 (帮忙文档)

    (1)准备软件 首先需要我们准备如下软件: SandCastle, 下载地址: http://sandcastle.codeplex.com/releases/view/47665 (2)准备项目文件 ...

  9. iOS开发 .framework的Optional(弱引用)和Required(强引用)区别

    首先,参考文档:https://blog.stackmob.com/2013/03/objective-c-tip-of-the-month-optional-frameworks/ 强引用(Requ ...

  10. Unity3D脚本中文系列教程(十五)

    http://dong2008hong.blog.163.com/blog/static/4696882720140322449780/ Unity3D脚本中文系列教程(十四) ◆ LightRend ...