题目链接

题意:给个N*N的矩形点,求在原点看去能看到多少个点

思路:除了(1,0),(0,1),(1,1)外其他点的xy都互质。所以求欧拉函数。fhi[i]从2加到n,再是两倍,再加3。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
using namespace std;
const int max_n=;
int v[max_n],prime[max_n],phi[max_n];
void euler(int n)
{
memset(v,,sizeof(v));
int m=;
for(int i=;i<=n;i++)
{
if(v[i]==)
{
v[i]=i;
prime[++m]=i;
phi[i]=i-;
}
for(int j=;j<=m;j++)
{
if(prime[j]>v[i]||prime[j]>n/i)
break;
v[i*prime[j]]=prime[j];
phi[i*prime[j]]=phi[i]*(i%prime[j]?prime[j]-:prime[j]);
}
}
}
int main()
{
int n;
euler();
int t; scanf("%d",&t);
int x=;
while(t--){
scanf("%d",&n);
long long sum=;
for(int i=;i<=n;i++)
sum+=phi[i];
sum=sum*+;
printf("%d ",++x);
printf("%d ",n);
printf("%lld\n",n==?0ll:sum);
}
}

Visible Lattice Points的更多相关文章

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

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

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

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

  3. poj 3060 Visible Lattice Points

    http://poj.org/problem?id=3090 Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Tota ...

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

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

  5. P8 Visible Lattice Points

    P8 Visible Lattice Points Time Limit:1000ms,     Memory Limit:65536KB Description A lattice point (x ...

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

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

  7. POJ3090 Visible Lattice Points

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

  8. Visible Lattice Points (莫比乌斯反演)

    Visible Lattice Points 题意 : 从(0,0,0)出发在(N,N,N)范围内有多少条不从重合的直线:我们只要求gcd(x,y,z) = 1; 的点有多少个就可以了: 比如 : 点 ...

  9. SPOJ1007 VLATTICE - Visible Lattice Points

    VLATTICE - Visible Lattice Points no tags  Consider a N*N*N lattice. One corner is at (0,0,0) and th ...

  10. SPOJ 7001. Visible Lattice Points (莫比乌斯反演)

    7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0, ...

随机推荐

  1. ubuntu搭建jdk+jenkins

    第一步,安装jdk(如果已安装,直接进行第二步) 1.下载 jdk-8u172-linux-x64.tar.gz       点此下载   2.解压 tar -zxvf jdk-8u172-linux ...

  2. C++ 测量程序执行时间的办法

    #include <time.h> clock_t start = clock(); //时间起始 /*待测试代码*/ clock_t end = clock(); //时间测试结束 co ...

  3. Validform验证插件

    http://validform.club/index.html

  4. mvc中@RenderSection()研究 转载https://www.cnblogs.com/rrxc/p/4062827.html

    一.@RenderSection定义 HelperResult RenderSection(string name) 但是当如果使用了_Layout.cshtml做母版页的页没有实现Section的话 ...

  5. 解决BootstrapTable设置height属性后,表格不对齐的问题

    解决BootstrapTable设置height属性后,表格不对齐的问题 2018年03月06日 09:56:54 nb7474 阅读数 5920     一般在使用BootstrapTable 插件 ...

  6. MyBatis中的$和#,用不好,准备走人!

    作者:程序猿的内心独白 https://m.toutiaocdn.com/i6685496024770806280 这是一次代码优化过程中发现的问题,在功能优化后发现部分数据查不到出来了,问题就在于一 ...

  7. NGUI的CheckBox的使用(toggle script)

    一,我们先添加一个sprite,选择sprite,右键选择attach,添加box collider, 然后右键选择attach,添加toggle script,得到如下图结果 1,但是如果你没有给U ...

  8. linux误用rm删除文件后恢复

    linux 系统:ubuntu16.04 误把/usr/local local文件删除了,要疯 步骤: 1.对于文件系统为ext3文件系统 sudo apt-get install ext3grep ...

  9. 【学习总结】认识MVC

    参考链接: 菜鸟教程-MVC模式 CSDN:浅谈MVC架构-你到底有什么本事 目录: 一.什么是MVC 1.概念 MVC全名是Model View Controller,是模型(model)-视图(v ...

  10. javascript中的toString()、toLocaleString()方法

    javascript中的toString()方法,主要用于Array.Boolean.Date.Error.Function.Number等对象.下面是这些方法的一些解析和简单应用,做个纪律,以作备忘 ...