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 ...
随机推荐
- CBAM: Convolutional Block Attention Module
1. 摘要 作者提出了一个简单但有效的注意力模块 CBAM,给定一个中间特征图,我们沿着空间和通道两个维度依次推断出注意力权重,然后与原特征图相乘来对特征进行自适应调整. 由于 CBAM 是一个轻量级 ...
- Vue实现音乐播放器(二)-Vue-cli脚手架安装
- 阶段1 语言基础+高级_1-3-Java语言高级_04-集合_01 Collection集合_6_迭代器的实现原理
- SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON 什么意思 sql server 2005 2008
原文:http://www.cnblogs.com/ForFreeDom/archive/2009/10/16/1584680.html 在sqlserver2005或SQL2008数据库项目中,创建 ...
- CentOSLinux系统中Ansible自动化运维的安装以及利用Ansible部署JDK和Hadoop
Ansible 安装和配置 Ansible 说明 Ansible 官网:https://www.ansible.com/ Ansible 官网 Github:https://github.com/an ...
- [随笔重写] Python3 的深拷贝与浅拷贝
1. Python3 关于深浅拷贝的官方文档 文档地址:Python3.7.2 源码地址:lib/copy.py 2. 先说结论 深拷贝与浅拷贝是对复合对象而言的 深拷贝会构造一个新的复合对象,然后递 ...
- flume 进阶
一.flume事务 put事务流程: 1.doPut:将批量数据先写入临时缓冲区putList 2.doCommit:检查Channel内存队列是否足够, (1)达到一定时间没有数据写入到putLis ...
- 小白学Python(16)——pyecharts 绘制地理图表 Geo
Geo-基本示例 from example.commons import Faker from pyecharts import options as opts from pyecharts.char ...
- 使用Webpack的代码分离实现Vue懒加载(译文)
当一个Vue的项目体积变得十分庞大的时候,使用Webpack的代码分离功能将Vue Components,routes或Vuex的代码进行分离并按需加载,会极大的提高App的首屏加载速度. 在Vue的 ...
- Vue+axios+Node+express实现文件上传(用户头像上传)
Vue 页面的代码 <label for='my_file' class="theme-color"> <mu-icon left value="bac ...