BZOJ3529 [Sdoi2014]数表【莫比乌斯反演】
Description
有一张 n×m 的数表,其第 i 行第 j 列(1 <= i <= n, 1 <= j <= m)的数值为
能同时整除 i 和 j 的所有自然数之和。给定 a , 计算数表中不大于 a 的数之和。
Input
输入包含多组数据。
输入的第一行一个整数Q表示测试点内的数据组数
接下来Q行,每行三个整数n,m,a(|a| < =10^9)描述一组数据。
1 < =N.m < =10^5  , 1 < =Q < =2×10^4
Output
对每组数据,输出一行一个整数,表示答案模2^31的值。
Sample Input
2
4 4 3
10 10 5
Sample Output
20
148
题解%%%%贝神的blog,我就不赘述了
//Author: dream_maker
#include<bits/stdc++.h>
using namespace std;
//----------------------------------------------
//typename
typedef long long ll;
//convenient for
#define fu(a, b, c) for (int a = b; a <= c; ++a)
#define fd(a, b, c) for (int a = b; a >= c; --a)
#define fv(a, b) for (int a = 0; a < (signed)b.size(); ++a)
//inf of different typename
const int INF_of_int = 1e9;
const ll INF_of_ll = 1e18;
//fast read and write
template <typename T>
void Read(T &x) {
  bool w = 1;x = 0;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') w = 0, c = getchar();
  while (isdigit(c)) {
    x = (x<<1) + (x<<3) + c -'0';
    c = getchar();
  }
  if (!w) x = -x;
}
template <typename T>
void Write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) Write(x / 10);
  putchar(x % 10 + '0');
}
//----------------------------------------------
const int N = 1e5 + 10;
int prime[N], mu[N], tot = 0;
bool vis[N];
int sum[N], pre[N], ans[N];
struct Ques {
  int n, m, id, a;
} Q[N];
bool operator < (const Ques a, const Ques b) {
  return a.a < b.a;
}
struct Node {
  int id, vl;
} P[N];
bool operator < (const Node a, const Node b) {
  return a.vl < b.vl;
}
void init() {
  mu[1] = sum[1] = pre[1] = 1;
  P[1] = (Node){1, 1};
  fu(i, 2, N - 1) {
    if (!vis[i]) {
      prime[++tot] = i;
      mu[i] = -1;
      sum[i] = pre[i] = i + 1;
    }
    fu(j, 1, tot) {
      int nxt = i * prime[j];
      if (nxt >= N) break;
      vis[nxt] = 1;
      if (i % prime[j]) {
        pre[nxt] = prime[j] + 1;
        sum[nxt] = sum[i] * sum[prime[j]];
        mu[nxt] = -mu[i];
      } else {
        pre[nxt] = pre[i] * prime[j] + 1;
        sum[nxt] = sum[i] / pre[i] * pre[nxt];
        mu[nxt] = 0;
        break;
      }
    }
    P[i] = (Node){i, sum[i]};
  }
}
int bit[N];
void add(int x, int vl) {
  for (; x < N; x += x & (-x)) bit[x] += vl;
}
int query(int x) {
  int res = 0;
  for (; x; x -= x & (-x)) res += bit[x];
  return res;
}
int main() {
  init();
  int T; Read(T);
  fu(i, 1, T) {
    Read(Q[i].n), Read(Q[i].m), Read(Q[i].a);
    Q[i].id = i;
  }
  sort(Q + 1, Q + T + 1);
  sort(P + 1, P + N);
  int now = 1;
  fu(i, 1, T) {
    while (now < N && P[now].vl <= Q[i].a) {
      fu(j, 1, (N - 1) / P[now].id) {
        add(j * P[now].id, mu[j] * P[now].vl);
      }
      ++now;
    }
    int limit = min(Q[i].n, Q[i].m), k = 0;
    for (int j = 1; j <= limit; j = k + 1) {
      k = min(Q[i].n / (Q[i].n / j), Q[i].m / (Q[i].m / j));
      ans[Q[i].id] += (Q[i].n / j) * (Q[i].m / j) * (query(k) - query(j - 1));
    }
  }
  fu(i, 1, T) {
    Write(ans[i] & 2147483647);
    putchar('\n');
  }
  return 0;
}
												
											BZOJ3529 [Sdoi2014]数表【莫比乌斯反演】的更多相关文章
- bzoj3529: [Sdoi2014]数表  莫比乌斯反演
		
题意:求\(\sum_{i=1}^n\sum_{j=1}^nf(gcd(i,j))(gcd(i,j)<=a),f(x)是x的因子和函数\) 先考虑没有限制的情况,考虑枚举gcd为x,那么有\(\ ...
 - BZOJ3529: [Sdoi2014]数表(莫比乌斯反演,离线)
		
Description 有一张 n×m 的数表,其第 i 行第 j 列(1 <= i <= n, 1 <= j <= m)的数值为 能同时整除 i 和 j 的所有自然数之和.给 ...
 - BZOJ3529: [Sdoi2014]数表(莫比乌斯反演 树状数组)
		
题意 题目链接 Sol 首先不考虑\(a\)的限制 我们要求的是 \[\sum_{i = 1}^n \sum_{j = 1}^m \sigma(gcd(i, j))\] 用常规的套路可以化到这个形式 ...
 - BZOJ3529: [Sdoi2014]数表 莫比乌斯反演_树状数组
		
Code: #include <cstdio> #include <algorithm> #include <cstring> #define ll long lo ...
 - bzoj [SDOI2014]数表 莫比乌斯反演 BIT
		
bzoj [SDOI2014]数表 莫比乌斯反演 BIT 链接 bzoj luogu loj 思路 \[ \sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}a*[f[ ...
 - 【BZOJ3529】[Sdoi2014]数表 莫比乌斯反演+树状数组
		
[BZOJ3529][Sdoi2014]数表 Description 有一张N×m的数表,其第i行第j列(1 < =i < =礼,1 < =j < =m)的数值为能同时整除i和 ...
 - 【bzoj3529】[Sdoi2014]数表  莫比乌斯反演+离线+树状数组
		
题目描述 有一张n×m的数表,其第i行第j列(1 <= i <= n ,1 <= j <= m)的数值为能同时整除i和j的所有自然数之和.给定a,计算数表中不大于a的数之和. ...
 - BZOJ 3259 [Sdoi2014]数表 (莫比乌斯反演 + 树状数组)
		
3529: [Sdoi2014]数表 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 2321 Solved: 1187[Submit][Status ...
 - BZOJ 3529: [Sdoi2014]数表 [莫比乌斯反演 树状数组]
		
3529: [Sdoi2014]数表 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1399 Solved: 694[Submit][Status] ...
 - BZOJ 3529 [Sdoi2014]数表 (莫比乌斯反演+树状数组+离线)
		
题目大意:有一张$n*m$的数表,第$i$行第$j$列的数是同时能整除$i,j$的所有数之和,求数表内所有不大于A的数之和 先是看错题了...接着看对题了发现不会做了...刚了大半个下午无果 看了Po ...
 
随机推荐
- RabbitMQ 的路由模式   Topic模式
			
模型 生产者 package cn.wh; import java.io.IOException; import java.util.concurrent.TimeoutException; impo ...
 - 全文检索引擎Solr系列——整合中文分词组件mmseg4j
			
默认Solr提供的分词组件对中文的支持是不友好的,比如:“VIM比作是编辑器之神”这个句子在索引的的时候,选择FieldType为”text_general”作为分词依据时,分词效果是: 它把每一个词 ...
 - bootstrap系统学习
			
1.响应式中注意的内容: 一行(row)必须在.container中. col-xs- col-sm- col-md- col-lg- 列偏移 .col-md-offset-* 列排序 .col-md ...
 - [嵌入式培训 笔记]-----Vim编辑器使用简介
			
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 第一讲小结 1. 光标在屏幕文本中的移动既 ...
 - 【转】ftrace 简介
			
ftrace 简介 ftrace 的作用是帮助开发人员了解 Linux 内核的运行时行为,以便进行故障调试或性能分析. 最早 ftrace 是一个 function tracer,仅能够记录内核的函数 ...
 - Gruntjs提高生产力(三)
			
以下例子来自真实项目,有所删减 grunt-test project 目录结构如下 一我的目的: 1.在src-dev目录中开发最终产出于src目录 2.src-dev中的index目录相当于一个wi ...
 - C语言调用DIRECT3D的实例代码,通过lpVtbl字段进行
			
m_pDirect3D9 = Direct3DCreate9(D3D_SDK_VERSION); int w = 1920; int h = 1080; D3DPRESENT_PARAMETER ...
 - HDU 4352 XHXJ's LIS ★(数位DP)
			
题意 求区间[L,R]内满足各位数构成的数列的最长上升子序列长度为K的数的个数. 思路 一开始的思路是枚举数位,最后判断LIS长度.但是这样的话需要全局数组存枚举的各位数字,同时dp数组的区间唯一性也 ...
 - leetcode 849. Maximize Distance to Closest Person
			
In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is emp ...
 - Maven 环境搭建及相应的配置
			
在一般的Java Web项目开发中,特别是基于Struts + hibernate + spring的框架的时候,会有很多的jar包,一般都会在项目文件中有一个lib文件夹,下面放所有相关的jar包. ...