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 ...
随机推荐
- Linux内核调试方法总结之内核通知链
Linux内核通知链notifier 1.内核通知链表简介(引用网络资料) 大多数内核子系统都是相互独立的,因此某个子系统可能对其它子系统产生的事件感兴趣.为了满足这个需求,也即是让某个子系统在 ...
- 《图解 TCP-IP(第 5 版)》
第一章 网络基础知识 计算机网络根据规模可以分为:广域网(WAN: Wide Area Network)和局域网(LAN: Local Area Network) 协议的标准化: 国际标准化组织(IS ...
- springMVC解决跨域
原文:https://www.cnblogs.com/shihaiming/p/9544060.html 介绍: 跨站 HTTP 请求(Cross-site HTTP request)是指发起请求 ...
- 《图解设计模式》读书笔记9-1 Flyweight模式
目录 模式简介 示例代码 代码功能与实现思路 类图 代码 结果图示分析 模式角色和类图 角色 类图 拓展思路 对多个地方产生影响 什么要共享,什么不要共享 垃圾回收 模式简介 Flyweight是轻量 ...
- JMeterContext----上下文
http://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html org.apache.jmeter.threads ...
- UI自动化之特殊处理二(弹框\下拉框\选项\文件上传)
弹框\下拉框\选项\文件上传也是一些比较特殊的操作 目录 1.弹框 2.下拉框 3.选项 4.文件上传 1.弹框 弹框有三种形式,value为alert.confirm.prompt三种的弹框,第一个 ...
- mac 添加mysql的环境变量和删除mysql
添加环境变量 1.创建 .bash_profile,已创建过忽略这步 (1)启动终端 (2)进入当前用户的home目录(默认就是): cd ~ 或 cd /Users/YourMacU ...
- 剑指offer--day08
1.1 题目:二叉树镜像:操作给定的二叉树,将其变换为源二叉树的镜像. 1.2 思路:先交换根节点的两个子结点之后,我们注意到值为10.6的结点的子结点仍然保持不变,因此我们还需要交换这两个结点的左右 ...
- 安全运维 - Linux系统攻击回溯
入侵排查思路 (1)- 日志分析 日志分析 默认日志路径: /var/log 查看日志配置情况: more /etc/rsyslog.conf 重要日志: 登录失败记录: /var/log/btmp ...
- C#打印单据
HTML: <form id="form1"> <div id="t_border"> <!- ...