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 ...
随机推荐
- tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
在执行自动化打包的时候报错,检查发现是Xcode的路径被改了 标记3的地方原来默认是没有内容的,点击它,然后会自动弹出一个选项,就是xcode的版本. 修改后,在命令行输入xcodebuild命令测试 ...
- 字符串中的TOUPPER函数
std::string& str_toupper(std::string& s) { std::transform(s.begin(), s.end(), s.begin(), []( ...
- base64编解码的两个函数
base64编解码的两个函数,声明,参考网络上的代码实现. unsigned char *base64_encode(unsigned char *str, long* lpBufLen) { lon ...
- 实验报告一 &第三周课程总结
实验报告 1.打印输出所有的“水仙花数”,所谓“水仙花数”是指一个3位数,其中各位数字立方和等于该数本身.例如,153是一个“水仙花数”. 实验代码: public class wdnmd{ publ ...
- [Python3 练习] 005 汉诺塔1 递归解法
题目:汉诺塔 I (1) 描述 传说,在世界中心贝拿勒斯(在印度北部)的圣庙外有左中右三根足够长的柱子(塔) 左边柱子上套着 64 片金片,金片按"上小下大"排,其余两根是空柱子 ...
- javascript自定义Map对象
javascript定义map对象开发前端组件的重要性就不过多阐述了,直接参考以下案例即可 <script type=text/javascript charset=utf-8> func ...
- display:table的几个用法 块级子元素垂直居中
DIV+CSS的布局已经让表格布局几乎很少用到,除非表格语义性很强的情况. display:table解决了一部分需要使用表格特性但又不需要表格语义的情况, 尤其是DIV+CSS很不方便解决的问题,比 ...
- mysql 可重复读
概念 Repeatable Read(可重复读):即:事务A在读到一条数据之后,此时事务B对该数据进行了修改并提交,那么事务A再读该数据,读到的还是原来的内容. 实现原理(MVCC [ 多版本并发控制 ...
- 如何在nuxt中添加proxyTable代理
背景 在本地开发vue项目的时候,当你习惯了proxyTable解决本地跨域的问题,切换到nuxt的时候,你会发现,添加了proxyTable设置并没有什么作用,那是因为你是用的vue脚手架生成的vu ...
- 洛谷 - P3649 - 回文串 - 回文自动机
https://www.luogu.org/problem/P3649 #include <bits/stdc++.h> using namespace std; typedef long ...