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

析:

其中,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. bbs项目引入富文本编辑器和处理xss攻击和文章预览

    一.富文本编辑上传文章和图片 富文本编辑器我们使用kindeditor,我们首先去官网下载,然后解压,放到我们的static的目录中 然后我们在html中这样使用富文本编辑器 <!DOCTYPE ...

  2. js中的循环

    js中的循环是我们经常要用到的,现在进行一些归纳. 一.javascript种的循环. 1.循环对象 var o = { name: 'Jack', age: 20, city: 'Beijing' ...

  3. 使用SQL语句创建数据库2——创建多个数据库文件和多个日志文件

    在matser数据库下新建查询,输入的命令如下: USE master GOCREATE DATABASE E_MarketON PRIMARY--主文件组( NAME ='E_Market_data ...

  4. MVC的Forms登录验证

    第一步:修改web.config配置 在 <system.web>节点下加入配置:未登录的用户跳转到/Home/Login,登录后跳转到/Home/UserCenter,登录后票证记录到c ...

  5. 在threejs中添加两个场景和相机是需要注意render的参数设置

    问题:我刚开始设置了两个场景和相机 但是第二个一直将第一个场景给覆盖了一直找不到原因 解决: 问题出在 renderer.autoClear = false;上 设置render的参数如下: rend ...

  6. linux 发送Post请求 json格式

    curl -H "Content-type: application/json" -X POST -d '{"text":"总体来说很不错,环境挺好的 ...

  7. C++命名空间学习笔记

    1 模块化和界面 任何实际程序都是有一些部分组成的.通过将程序进行模块化可以使我们的程序更加清晰,有助于多人合作和维护. 将一个程序进行模块化以后,当其中一个模块调用另一个模块时,它不需要知道其具体实 ...

  8. fastdfs 上传图片 完整版

    1.jsp文件 <%@ page language="java" import="java.util.*" pageEncoding="UTF- ...

  9. Java.Class

    Class类 1. Class继承自Object. 2. .class 和 instance.getClass()的区别 Ref[1] Reference 1. .class http://stack ...

  10. p值还是 FDR ?

    p值还是 FDR ? 差异分析 如何筛选显著性差异基因,p value, FDR 如何选 经常有同学询问如何筛选差异的基因(蛋白).已经计算了表达量和p value值,差异的基因(蛋白)太多了,如何筛 ...