SPOJ VLATTICE - Visible Lattice Points 【“小”大数加减】
一道比较简单的莫比乌斯反演,不过ans会爆long long,我是用结构体来存结果的,结构体中两个LL型变量分别存大于1e17和小于1e17的部分
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1e6;
];
];
];
void init()
{
mu[]=;
;
;i<=maxn;i++)
{
if(!check[i])
{
prime[tot++]=i;
mu[i]=-;
}
;j<tot;j++)
{
if(i*prime[j]>maxn) break;
check[i*prime[j]]=true;
)
{
mu[i*prime[j]]=;
break;
}
else
{
mu[i*prime[j]]=-mu[i];
}
}
}
}
LL n;
const LL mod=1e17;
struct node
{
LL a,b;
node(LL a_=,LL b_=)
{
a=a_,b=b_;
}
void print()
{
if(a) printf("%lld%017lld\n",a,b);
else printf("%lld\n",b);
}
};
node add(node x,LL y)
{
)
{
LL t1=(x.b+y)/mod;
LL t2=(x.b+y)%mod;
x.a+=t1,x.b=t2;
return x;
}
else
{
LL t1=(x.b+y)/mod;
LL t2=(x.b+y)%mod;
&&t2<) t2+=mod,t1--;
x.a+=t1,x.b=t2;
return x;
}
}
int main()
{
init();
int T;
node t;
LL x;
scanf("%d",&T);
while(T--)
{
scanf("%lld",&n);
node ans;
;i<=n;i++)
ans=add(ans,mu[i]*(n/i)*(n/i)*(n/i));
;i<=n;i++)
ans=add(ans,mu[i]*(n/i)*(n/i)*);
ans=add(ans,);
ans.print();
}
}
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 数论 莫比乌斯反演
7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0, ...
- 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(莫比乌斯反演)题解
题意: 有一个\(n*n*n\)的三维直角坐标空间,问从\((0,0,0)\)看能看到几个点. 思路: 按题意研究一下就会发现题目所求为. \[(\sum_{i=1}^n\sum_{j=1}^n\su ...
- 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 7001. Visible Lattice Points GCD问题 莫比乌斯反演
SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...
- Spoj 7001 Visible Lattice Points 莫比乌斯,分块
题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193 Visible Lattice Points Time L ...
随机推荐
- vue +ts 的一次踩坑日记
在vue的方法里面写事件的时候比如写一个路由跳转,方法大概如下: goBack1() { console.log(this); this.$router. ...
- 老外写的-用Rawrite神器写入u盘镜像-制作u盘启动- fedora -u盘安装制作
用Rawrite神器写入u盘镜像? ====================================================== 尝试用ultraiso, 写入硬盘镜像, 不能启动,在 ...
- 查看磁盘和文件的使用情况df和du
df, du: disk filesystem, disk usage. df : 查看一级目录的使用情况, df -h du: 则是可以查看目录或者某个文件的占用磁盘空间的情况, du -h: 使用 ...
- LongAdder 源码分析
LongAdder LongAdder 能解决什么问题?什么时候使用 LongAdder? 1)LongAdder 内部包含一个基础值[base]和一个单元[Cell]数组. 没有竞争的情况下,要累加 ...
- ES6模块与CommonJS模块的差异
ES6模块与CommonJS模块的差异 讨论 Node 加载 ES6模块之前,必须了解 ES6模块与 CommonJS模块完全不同. 它们有两个重大差异. CommonJS模块输出的是一个值的拷贝,E ...
- window.open弹窗阻止问题解决之道
https://segmentfault.com/a/1190000015381923https://segmentfault.com/a/1190000014988094https://www.cn ...
- Java 高级-集合框架
参考资料 参考 HashMap 类似 C++ 中的 STL 标准模板库,Java 也在 java.util 包中封装了一套常用数据结构及其算法,称为集合框架.所有的集合框架都包含如下内容: 接口:代表 ...
- 【ABAP系列】SAP ABAP实现发送外部邮件(添加附件)功能
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP ABAP实现发送外部邮件(添 ...
- logstash异常
logstash异常 1 2 3 Unrecognized VM option 'UseParNewGC' Error: Could not create the Java Virtual Machi ...
- windows和linux中查看端口占用情况并kill掉对应进程
好几次在不同的情况下遇到 需要查看端口信息 并且kill掉对应进程的情况 相关的参数总是记不全 在这里记录下 以后查看方便 windows中查看正在使用端口的信息netstat -ano|findst ...