SPOJ VLATTICE Visible Lattice Points 莫比乌斯反演
这样的点分成三类
1 不含0,要求三个数的最大公约数为1
2 含一个0,两个非零数互质
3 含两个0,这样的数只有三个,可以讨论
针对 1情况 定义f[n]为所有满足三个数最大公约数为n的三元组数量
F[n]为所有满足三个数的最大公约数能被n整除的三元组数量
显然 F[n]=∑n|df[d]
然后由莫比乌斯反演,f[n]=∑n|dμ[d/n]*F[d]
情况三也是一样的
- #include<iostream>
- #include<algorithm>
- #include<set>
- #include<vector>
- #include<queue>
- #include<cstdlib>
- #include<cstdio>
- #include<cstring>
- #include<cmath>
- using namespace std;
- typedef long long LL;
- typedef unsigned long long ULL;
- const int N=1e6+;
- int n,T,prime[N],mu[N];
- bool vis[N];
- void getmu()
- {
- mu[] = ;
- int cnt = ;
- for(int i=; i<=N-; i++)
- {
- if(!vis[i])
- {
- prime[cnt++] = i;
- mu[i] = -;
- }
- for(int j=; j<cnt&&i*prime[j]<=N-; j++)
- {
- vis[i*prime[j]] = ;
- if(i%prime[j]) mu[i*prime[j]] = -mu[i];
- else
- {
- mu[i*prime[j]] = ;
- break;
- }
- }
- }
- }
- LL F1(LL x){
- x=n/x;
- return x*x*x;
- }
- LL F2(LL x){
- x=n/x;
- return x*x*;
- }
- int main(){
- getmu();
- scanf("%d",&T);
- while(T--){
- scanf("%d",&n);
- LL ans=;
- for(int i=;i<=n;++i){
- ans+=mu[i]*F1(i);
- ans+=mu[i]*F2(i);
- }
- printf("%lld\n",ans+);
- }
- return ;
- }
SPOJ VLATTICE Visible Lattice Points 莫比乌斯反演的更多相关文章
- 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 莫比乌斯反演 难度: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 7001 Visible Lattice Points莫比乌斯反演
Visible Lattice Points Time Limit:7000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Su ...
- SPOJ 7001 Visible Lattice Points (莫比乌斯反演)
题意:求一个正方体里面,有多少个顶点可以在(0,0,0)位置直接看到,而不被其它点阻挡.也就是说有多少个(x,y,z)组合,满足gcd(x,y,z)==1或有一个0,另外的两个未知数gcd为1 定义f ...
- [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 Visible Lattice Points 莫比乌斯,分块
题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193 Visible Lattice Points Time L ...
- spoj7001 Visible Lattice Points 莫比乌斯反演+三维空间互质对数
/** 题目:Visible Lattice Points 链接:https://vjudge.net/contest/178455#problem/A 题意:一个n*n*n大小的三维空间.一侧为(0 ...
- SPOJ VLATTICE Visible Lattice Points(莫比乌斯反演)题解
题意: 有一个\(n*n*n\)的三维直角坐标空间,问从\((0,0,0)\)看能看到几个点. 思路: 按题意研究一下就会发现题目所求为. \[(\sum_{i=1}^n\sum_{j=1}^n\su ...
- SPOJ VLATTICE - Visible Lattice Points 【“小”大数加减】
题目链接 一道比较简单的莫比乌斯反演,不过ans会爆long long,我是用结构体来存结果的,结构体中两个LL型变量分别存大于1e17和小于1e17的部分 #include<bits/stdc ...
随机推荐
- HaProxy+keepalived实现负载均衡
HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保持 ...
- 解决VS2008打开假死或者打开设计模式假死的问题
我昨天刚装完OFFICE 2010一直也没重启,vs2008是可以使用的.今早来到办公室,打开工程发现开了半天VS2008一般空白,查看应用程序显示正在运行,再查看进程发现里面多一个setup.exe ...
- Cassandra1.2文档学习(7)—— 规划集群部署
数据参考:http://www.datastax.com/documentation/cassandra/1.2/webhelp/index.html#cassandra/architecture/a ...
- 003.XE3包含了TPerlRegEx的单元
使用'|'替换所有的内容 代码: program Project1; {$APPTYPE CONSOLE} uses System.SysUtils, System.RegularExpression ...
- Python 爬虫入门(requests)
相信最开始接触Python爬虫学习的同学最初大多使用的是urllib,urllib2.在那之后接触到了第三方库requests,requests完全能满足各种http功能,真的是好用爆了 :D 他们是 ...
- php中一些安全性防止问题建议
只要我们作好了各类操作就可在基本防止一些朋友利用网站本身的漏洞进行网站操作了,很多在php中都有的如XSS用 htmlentities()预防XSS攻击还有sql注入可以用mysql_real_esc ...
- 什么是UI控件
凡是带有Widget参数的组件都是控件.
- ios更改UITabBarController背景以及选中背景图片的方法
一.背景图片 1.5.0以上版本 UIImage *image = [UIImage imageNamed:@"system_tabbar_bg.png"]; [ ...
- xss攻击入门
xss表示Cross Site Scripting(跨站脚本攻击),它与SQL注入攻击类似,SQL注入攻击中以SQL语句作为用户输入,从而达到查询/修改/删除数据的目的,而在xss攻击中,通过插入恶意 ...
- PHP漏洞全解(八)-HTTP响应拆分
本文主要介绍针对PHP网站HTTP响应拆分,站在攻击者的角度,为你演示HTTP响应拆分. HTTP请求的格式 1)请求信息:例如“Get /index.php HTTP/1.1”,请求index.ph ...