题意:给定上一个数组,求

析:

其中,f(d)表示的是gcd==d的个数,然后用莫比乌斯反演即可求得,len[i]表示能整队 i 的个数,可以线性筛选得到,

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
//#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e4 + 5;
const int maxm = 2e4 + 10;
const LL mod = 10007;
const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} int a[maxn], len[maxn];
bool vis[maxn];
int prime[maxn], mu[maxn]; void Moblus(){
mu[1] = 1;
int tot = 0;
for(int i = 2; i < maxn; ++i){
if(!vis[i]) prime[tot++] = i, mu[i] = -1;
for(int j = 0; j < tot; ++j){
int t = i * prime[j];
if(t >= maxn) break;
vis[t] = 1;
if(i % prime[j] == 0) break;
mu[t] = -mu[i];
}
}
} int f[maxn]; int main(){
Moblus();
while(scanf("%d", &n) == 1){
ms(a, 0); ms(len, 0); ms(f, 0);
for(int i = 0; i < n; ++i){
int x; scanf("%d", &x);
++a[x];
} for(int i = 1; i < maxn; ++i)
for(int j = i; j < maxn; j += i)
len[i] += a[j];
for(int i = 1; i < maxn; ++i)
for(int j = i, cnt = 1; j < maxn; j += i, ++cnt)
f[i] += mu[cnt] * sqr(len[j]);
LL ans = 0;
for(int i = 2; i < maxn; ++i)
ans = (ans + i * (i-1) * (LL)f[i]) % mod;
printf("%lld\n", ans);
}
return 0;
}

  

HDU 5212 Code (莫比乌斯反演)的更多相关文章

  1. hdu.5212.Code(莫比乌斯反演 && 埃氏筛)

    Code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submi ...

  2. POJ3094 Sky Code(莫比乌斯反演)

    POJ3094 Sky Code(莫比乌斯反演) Sky Code 题意 给你\(n\le 10^5\)个数,这些数\(\le 10^5\),问这些这些数组成的互不相同的无序四元组(a,b,c,d)使 ...

  3. HDU 5212 Code【莫比乌斯反演】

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5212 题意: 给定序列,1≤i,j≤n,求gcd(a[i],a[j])∗(gcd(a[i],a[j] ...

  4. HDU 4746 Mophues (莫比乌斯反演应用)

    Mophues Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327670/327670 K (Java/Others) Total ...

  5. [HDU 5608]Function(莫比乌斯反演 + 杜教筛)

    题目描述 有N2−3N+2=∑d∣Nf(d)N^2-3N+2=\sum_{d|N} f(d)N2−3N+2=∑d∣N​f(d) 求∑i=1Nf(i)\sum_{i=1}^{N} f(i)∑i=1N​f ...

  6. hdu 1695 GCD 莫比乌斯反演入门

    GCD 题意:输入5个数a,b,c,d,k;(a = c = 1, 0 < b,d,k <= 100000);问有多少对a <= p <= b, c <= q <= ...

  7. HDU 1695 GCD 莫比乌斯反演

    分析:简单的莫比乌斯反演 f[i]为k=i时的答案数 然后就很简单了 #include<iostream> #include<algorithm> #include<se ...

  8. POJ 3904 JZYZOJ 1202 Sky Code 莫比乌斯反演 组合数

    http://poj.org/problem?id=3904   题意:给一些数,求在这些数中找出四个数互质的方案数.   莫比乌斯反演的式子有两种形式http://blog.csdn.net/out ...

  9. Mophues HDU - 4746 (莫比乌斯反演)

    Mophues \[ Time Limit: 10000 ms\quad Memory Limit: 262144 kB \] 题意 求出满足 \(gcd\left(a,b\right) = k\), ...

随机推荐

  1. apache jmeter 压力测试

    前面讲了linux下的压力测试,今天来个windows下的,用jmeter为例 我用了两个apache-jmeter-3.1和apache-jmeter-4.0分别进行了测试, 前者高并发电脑卡死时间 ...

  2. swift - 使用系统app导航

    import UIKit //1.导入框架 import MapKit class ViewController: UIViewController { lazy var geoCoder : CLG ...

  3. SCP对拷如何连接指定端口远程主机

    SCP对拷如何连接指定端口(非22端口)的远程主机 scp  -P  远程端口号  本机待拷贝文件路径 远程主机用户名@远程主机地址:远程主机目的路径 注意:  1.  参数-P 的位置一定要紧跟在s ...

  4. php解析优酷网上的视频资源去广告

    1.过程原理解析: 一.准备工作 所谓工欲善其事必先利其器,做好破解的准备工作会令你事半功倍. 1.首先准备一个Http抓包工具,PC上推荐Fiddler或者Postman,iOS上推荐Surge 2 ...

  5. MyBatis延迟加载和缓存(4)

    一.项目创建 1.项目目录结构 2.数据库配置和上一篇的一样,这里不再描述.下面创建mybatis配置文件SqlMapConfig.xml <?xml version="1.0&quo ...

  6. Js学习(2)数据类型

    Js共有六种数据类型(ES6又增加了第七种Symbol类型的值): 原始类型:数值,字符串,布尔值 合成类型:对象(object):各种值组成的集合 其他undefined,null 对象又可以分成三 ...

  7. go语言中container容器数据结构heap、list、ring

    heap堆的使用: package main import ( "container/heap" "fmt" ) type IntHeap []int //我们 ...

  8. Ubuntu 16.04 更换阿里源

    vim /etc/apt/source.list deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by s ...

  9. openshift上传java web项目

    下载当前客户端 OC(Openshift Client) https://mirror.openshift.com/pub/openshift-v3/clients/3.9.14/windows/oc ...

  10. python3.6.5 路径处理与规范化

    在Linux和Mac平台上,该函数会原样返回path,在windows平台上会将路径中所有字符转换为小写,并将所有斜杠转换为饭斜杠. >>> os.path.normcase('c: ...