bzoj2818: Gcd懵逼乌斯反演】的更多相关文章

由于是单组数据,强行不分块O(n)过 线性筛部分非常神奇,用了一个奇妙的推导(懒得写了) #include <bits/stdc++.h> using namespace std; ],f[],p[];]; int main() { scanf("%d",&n); mu[]=; ;i<=n;i++) { ,f[i]=; ;j<=m;j++) if((long long)p[j]*i<=(long long)n) { o[p[j]*i]=; ) f[…
属于结果的和好求但是结果不好求的题 (轻易能得到以k的倍数为最大公约数的对数,但是不好直接求k) 所以一波反演结束 其实反演的时候完全没有反演的感觉,就是不停地恒等变形 算是懵逼乌斯反演最简单的例题 #include <bits/stdc++.h> using namespace std; ],p[];]; int calc(int n,int m) { ;if(n>m) swap(n,m); ,j;i<=n;i=j+) { j=min(n/(n/i),m/(m/i)); ret+…
一通套路之后得到 求出中间那个函数的前缀和的话就可以整除分块了. 暴力求的话复杂度其实很优秀了,大约在n~nlogn之间. 不过可以线性筛做到严格线性.考虑其最小质因子,如果是平方因子那么只有其有贡献,否则由于多了一个质因子,将函数值取反并加上该质因子贡献. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #includ…
[CJOJ2512]gcd之和(莫比乌斯反演) 题面 给定\(n,m(n,m<=10^7)\) 求 \[\sum_{i=1}^n\sum_{j=1}^mgcd(i,j)\] 题解 首先把公因数直接提出来 \[\sum_{d=1}^nd\sum_{i=1}^{n/d}\sum_{j=1}^{m/d}[gcd(i,j)==1]\] 很明显 设 \[f(x)=\sum_{i=1}^{a}\sum_{j=1}^{b}[gcd(i,j)==x]\] \[g(x)=\sum_{x|d}f(d)\] \[g(…
题面 题意都在题目里面了 题解 你可以把题意看成这个东西 $$ \sum_{i=1}^n\sum_{j=1}^m\mathbf f(gcd(i,j)) $$ 其中$\mathbf f(n)$为$是否是一个质数[n是否是一个质数]$ 然后把$\mathbf f$反演一下,找到一个$\mathbf g$令$\mathbf f=\mathbf 1 \ast \mathbf g$,即: $$ \mathbf g(n)=\sum_{d\mid n}\mu(\frac nd)\cdot \mathbf f(…
分析:筛素数,然后枚举,莫比乌斯反演,然后关键就是分块加速(分块加速在上一篇文章) #include<cstdio> #include<cstring> #include<queue> #include<cstdlib> #include<algorithm> #include<vector> #include<cmath> using namespace std; typedef long long LL; ; cons…
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MB Submit: 6826 Solved: 3013 [Submit][Status][Discuss] Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的 数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 Sample Output 4 HINT hint 对于样例(2,2),(2,4),(3,3),(4,2) 1…
思路是hdu6134的简化版,只需要在外面套上一个枚举素数就行了. http://www.cnblogs.com/autsky-jadek/p/7491730.html #include<cstdio> using namespace std; #define N 10000000 bool notpri[N+5]; int pri[N+5],mu[N+5],sum[N+5]; typedef long long ll; void shai_mu() { notpri[1]=1; mu[1]=…
题目:GCD SUM 题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=39872 算法:莫比乌斯反演.优化 #include<stdio.h> #define N 100001 typedef long long LL; }; ; int mu[N]; LL f[N],ff[N]; //缩短时间 /* 莫比乌斯函数mu[i]的定义: 1. 如果 i 是素数,那么mu[i]为-1; 2. 如果 i 是由多个不同的素数组成的,那么mu[i]为-1…
Sum Of Gcd 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4676 Description Given you a sequence of number a1, a2, ..., an, which is a permutation of 1...n. You need to answer some queries, each with the following format: Give you two numbers L, R, y…