Bzoj 2190 仪仗队(莫比乌斯反演)
题面
题解
看这个题先大力猜一波结论
#include <cstdio>
#include <cstring>
#include <algorithm>
using std::min; using std::max;
using std::swap; using std::sort;
using std::__gcd;
typedef long long ll;
template<typename T>
void read(T &x) {
int flag = 1; x = 0; char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }
while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= flag;
}
const int N = 4e4 + 10;
int n, ret;
bool a[N][N];
int main () {
#ifdef OFFLINE_JUDGE
freopen("233.in", "r", stdin);
freopen("233.out", "w", stdout);
#endif
scanf("%d", &n);
for(int i = 2; i <= n; ++i)
for(int j = 2; j <= n; ++j) {
int tmp = __gcd(i, j);
int tmpi = i / tmp, tmpj = j / tmp;
if(!a[tmpi][tmpj]) ++ret, a[tmpi][tmpj] = true;
}
printf("%d\n", ret + 2);
return 0;
}
然后:

很接近了,仔细一想,应该是:
#include <cstdio>
#include <cstring>
#include <algorithm>
using std::min; using std::max;
using std::swap; using std::sort;
using std::__gcd;
typedef long long ll;
template<typename T>
void read(T &x) {
int flag = 1; x = 0; char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }
while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= flag;
}
const int N = 4e4 + 10;
int n, ret;
bool a[N][N];
int main () {
#ifdef OFFLINE_JUDGE
freopen("233.in", "r", stdin);
freopen("233.out", "w", stdout);
#endif
scanf("%d", &n);
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j) {
int tmp = __gcd(i, j);
if(tmp == 1) ++ret/*, a[tmpi][tmpj] = true*/;
}
printf("%d\n", ret);
return 0;
}
然后过了:

那不就是$Bzoj1101\ Zap$了,直接蒯(注意特判一下$n==1$的情况)
#include <cstdio>
#include <cstring>
#include <algorithm>
using std::min; using std::max;
using std::swap; using std::sort;
typedef long long ll;
template<typename T>
void read(T &x) {
int flag = 1; x = 0; char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }
while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= flag;
}
const int N = 4e4 + 10;
int t, n, mu[N], g[N], prime[N], cnt;
long long sum[N]; bool notprime[N];
void getmu(int k) {
mu[1] = 1;
for(int i = 2; i <= k; ++i) {
if(!notprime[i]) prime[++cnt] = i, mu[i] = -1;
for(int j = 1; j <= cnt && prime[j] * i <= k; ++j) {
notprime[prime[j] * i] = true;
if(!(i % prime[j])) break;
mu[prime[j] * i] = -mu[i];
}
}
for(int i = 1; i <= k; ++i)
sum[i] = sum[i - 1] + 1ll * mu[i];
}
int main () {
#ifdef OFFLINE_JUDGE
freopen("233.in", "r", stdin);
freopen("233.out", "w", stdout);
#endif
getmu(40000);
read(n); ll ans = n > 1 ? 2 : 0; --n;
for(int l = 1, r; l <= n; l = r + 1) {
r = n / (n / l);
ans += (sum[r] - sum[l - 1]) * (n / l) * (n / l);
}
printf("%lld\n", ans);
return 0;
}
Bzoj 2190 仪仗队(莫比乌斯反演)的更多相关文章
- bzoj [SDOI2014]数表 莫比乌斯反演 BIT
bzoj [SDOI2014]数表 莫比乌斯反演 BIT 链接 bzoj luogu loj 思路 \[ \sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}a*[f[ ...
- bzoj 2440 简单莫比乌斯反演
题目大意: 找第k个非平方数,平方数定义为一个数存在一个因子可以用某个数的平方来表示 这里首先需要考虑到二分才可以接下来做 二分去查找[1 , x]区间内非平方数的个数,后面就是简单的莫比乌斯反演了 ...
- bzoj 1101 Zap —— 莫比乌斯反演
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 直接莫比乌斯反演. 代码如下: #include<cstdio> #inc ...
- BZOJ 2818 Gcd (莫比乌斯反演 或 欧拉函数)
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MB Submit: 2534 Solved: 1129 [Submit][Status][Discu ...
- Bzoj 2818: Gcd(莫比乌斯反演)
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MB Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的 数对 ...
- $BZOJ$2818 $gcd$ 莫比乌斯反演/欧拉函数
正解:莫比乌斯反演/欧拉函数 解题报告: 传送门$QwQ$ 一步非常显然的变形,原式=$\sum_{d=1,d\in prim}^{n}\sum_{i=1}^{n}\sum_{j=1}^{n}[gcd ...
- bzoj 2190 仪仗队(欧拉函数)
2190: [SDOI2008]仪仗队 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 2245 Solved: 1413[Submit][Statu ...
- BZOJ 2440 完全平方数(莫比乌斯反演,容斥原理)
http://www.lydsy.com/JudgeOnline/problem.php?id=2440 题意:求第K个没有平方因子的数 思路:首先,可以二分数字,然后问题就转变成x以内有多少无平方因 ...
- [bzoj] 2694 Lcm || 莫比乌斯反演
原题 定义整数a,b,求所有满足条件的lcm(a,b)的和: 1<=a<=A 1<=b<=B ∀n>1,n2†gcd(a,b)(即任意n>1,\(n^2\)不是gc ...
随机推荐
- jQuery简单日历插件版
先来看demo:http://codepen.io/jonechen/pen/xOgZMz 插件代码: ; (function($) { var Calendar = function(ele, op ...
- 【BZOJ】3971 [WF2013]Матрёшка
[算法]区间DP [题解] 参考写法:BZOJ 3971 Матрёшка 解题报告 第二个DP可以预处理mex优化到O(nM+n2),不过我懒…… 第一个DP有另一种写法:不预处理,在一个n2取出来 ...
- windows phone 8.1如何访问应用商店,商店评论的连接
Windows Phone 8.1 中可以使用这个链接跳转到应用评论页面: await Windows.System.Launcher.LaunchUriAsync( new Uri("ms ...
- 深入理解 Java 多线程核心知识:跳槽面试必备
多线程相对于其他 Java 知识点来讲,有一定的学习门槛,并且了解起来比较费劲.在平时工作中如若使用不当会出现数据错乱.执行效率低(还不如单线程去运行)或者死锁程序挂掉等等问题,所以掌握了解多线程至关 ...
- 透彻理解Spring事务设计思想之手写实现(山东数漫江湖)
前言 事务,是描述一组操作的抽象,比如对数据库的一组操作,要么全部成功,要么全部失败.事务具有4个特性:Atomicity(原子性),Consistency(一致性),Isolation(隔离性),D ...
- springcloud(一):大话Spring Cloud(山东数漫江湖)
研究了一段时间spring boot了准备向spirng cloud进发,公司架构和项目也全面拥抱了Spring Cloud.在使用了一段时间后发现Spring Cloud从技术架构上降低了对大型系统 ...
- Django【进阶】分页功能Pagination
项目中,我们需要很多非业务逻辑的功能,例如分页功能,而且此类功能移植性很好,可以在不同的项目中使用,所以整理好这些功能会一定程度上提高开发效率,下面是分页功能代码,使用时,可单独放在utils目录 & ...
- selenium===splinter模块和selenium异曲同工
学习文档: http://splinter.readthedocs.io/en/latest/ 安装以后用它来实现163邮箱的登陆操作:*和selenium一样,splinter同样需要对frame进 ...
- ktime使用例子【原创】
#include <linux/kernel.h>#include <linux/init.h>#include <linux/module.h>#include ...
- mac os x 把reids nignx mongodb做成随机启动吧
~/Library/LaunchAgents 由用户自己定义的任务项 /Library/LaunchAgents 由管理员为用户定义的任务项 /Library/LaunchDaemons 由管理员定义 ...