[SPOJ7001]VLATTICE - Visible Lattice Points
题目大意:
$q(q\leq50)$组询问,对于给定的$n(n\leq10^7)$,求$\displaystyle\sum_{i=0}^n\sum_{j=0}^n\sum_{k=0}^n[\gcd(i,j,k)=1]$。
思路:
$原式=\sum_{d=1}^n(\lfloor\frac{n}{d}\rfloor^3+3\lfloor\frac{n}{d}\rfloor^2+3\lfloor\frac{n}{d}\rfloor)\mu(d)$。数论分块即可。
#include<cstdio>
#include<cctype>
typedef long long int64;
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
const int N=,M=;
bool vis[N];
int mu[N],sum[N],p[M];
inline void sieve() {
mu[]=;
for(register int i=;i<N;i++) {
if(!vis[i]) {
p[++p[]]=i;
mu[i]=-;
}
for(register int j=;j<=p[]&&i*p[j]<N;j++) {
vis[i*p[j]]=true;
if(i%p[j]==) {
mu[i*p[j]]=;
break;
} else {
mu[i*p[j]]=-mu[i];
}
}
}
for(register int i=;i<N;i++) {
sum[i]=sum[i-]+mu[i];
}
}
int main() {
sieve();
for(register int T=getint();T;T--) {
const int n=getint();
int64 ans=;
for(register int i=,j;i<=n;i=j+) {
j=n/(n/i);
ans+=(sum[j]-sum[i-])*((int64)(n/i)*(n/i)*(n/i)+(int64)(n/i)*(n/i)*+(n/i)*);
}
printf("%lld\n",ans);
}
return ;
}
原式=\sum_{d=1}^n(\lfloor\frac{n}{d}\rfloor^3+3\lfloor\frac{n}{d}\rfloor^2+3\lfloor\frac{n}{d}\rfloor)\mu(d)$。数论分块即可。
[SPOJ7001]VLATTICE - Visible Lattice Points的更多相关文章
- 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 ...
- SPOJ VLATTICE Visible Lattice Points (莫比乌斯反演基础题)
Visible Lattice Points Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at ...
- [SPOJ VLATTICE]Visible Lattice Points 数论 莫比乌斯反演
7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0, ...
- SPOJ 7001 VLATTICE - Visible Lattice Points(莫比乌斯反演)
题目链接:http://www.spoj.com/problems/VLATTICE/ 题意:求gcd(a, b, c) = 1 a,b,c <=N 的对数. 思路:我们令函数g(x)为g ...
- SPOJ—VLATTICE Visible Lattice Points(莫比乌斯反演)
http://www.spoj.com/problems/VLATTICE/en/ 题意: 给一个长度为N的正方形,从(0,0,0)能看到多少个点. 思路:这道题其实和能量采集是差不多的,只不过从二维 ...
- SPOJ VLATTICE Visible Lattice Points 莫比乌斯反演 难度:3
http://www.spoj.com/problems/VLATTICE/ 明显,当gcd(x,y,z)=k,k!=1时,(x,y,z)被(x/k,y/k,z/k)遮挡,所以这道题要求的是gcd(x ...
- SPOJ VLATTICE Visible Lattice Points 莫比乌斯反演
这样的点分成三类 1 不含0,要求三个数的最大公约数为1 2 含一个0,两个非零数互质 3 含两个0,这样的数只有三个,可以讨论 针对 1情况 定义f[n]为所有满足三个数最大公约数为n的三元组数量 ...
- SPOJ VLATTICE - Visible Lattice Points 【“小”大数加减】
题目链接 一道比较简单的莫比乌斯反演,不过ans会爆long long,我是用结构体来存结果的,结构体中两个LL型变量分别存大于1e17和小于1e17的部分 #include<bits/stdc ...
- SPOJ VLATTICE Visible Lattice Points(莫比乌斯反演)题解
题意: 有一个\(n*n*n\)的三维直角坐标空间,问从\((0,0,0)\)看能看到几个点. 思路: 按题意研究一下就会发现题目所求为. \[(\sum_{i=1}^n\sum_{j=1}^n\su ...
随机推荐
- 第5模块闯关CSS练习题
1.列举你知道的css选择器? 说道css选择器,大家都知道有许多种,但是真要你去掰着手指头数一数的话,你可能需要数几分钟.其实这么多选择器,完全可以分为两类: 标签选择器(*是特殊情况),可但标签, ...
- java高级编程技巧
1. boolean a= b==null;这句话很亮. public class Test { public static void main(String[] args) { String b=& ...
- 实时视频h5
http://www.cnblogs.com/dotfun/p/4286878.html
- UNIX 系统中 wc 程序的主要部分
以下代码为 UNIX 系统中 wc 程序的骨干部分 #include <stdio.h> #define IN 1 #define OUT 0 int main(int argc, cha ...
- Github问题An error occurred trying to download
Github for windows安装过程出现了这样的问题An error occurred trying to download 'http://github-windows.s3.amazona ...
- 最少的硬币数量组合出1到m之间的任意面值(贪心算法)
题目描述: 你有n种不同面值的硬币,每种面值的硬币都有无限多个,为了方便购物,你希望带尽量少的硬币,并且要能组合出 1 到 m 之间(包含1和m)的所有面值. 输入描述: 第一行包含两个整数:m ,n ...
- Visual C++斗地主游戏网络版源代码
说明:VC++ 6.0写的网络版斗地主游戏,程序基于directx SDK开发,因此你在编译时需要引入相应文件才可以,本斗地主可以支持双人对战.网络对战,游戏随机产生地主,动画发牌,界面也不错,还有声 ...
- [ecmagnet][python基础]有关git那些事
#1 git教程 # 注册git服务器用户,权限-- 注意这个和客户端用户不是一样 # 客户端(linux)提交代码到本地仓库(简单版,了解原理) a.安装git sudo apt-get insta ...
- HDU5857 Median 模拟
Median HDU - 5857 There is a sorted sequence A of length n. Give you m queries, each one contains fo ...
- Android view相关与自定义View
一.关于view的机制的问答 1.gesturedetector和ontouchevent的区别 gesturedetector指的是手势检测器,根据动态手势的运动特性,提出了速率边沿检测算法来分割手 ...