Crash的数字表格 BZOJ 2154 / jzptab BZOJ 2693
jzptab
【问题描述】
求:

多组询问
【输入格式】
一个正整数T表示数据组数
接下来T行 每行两个正整数 表示N、M
【输出格式】
T行 每行一个整数 表示第i组数据的结果
【样例输入】
1
4 5
【样例输出】
122
【数据范围】
T <= 10000
N, M<=10000000
题解:



即后面那个部分为 H[T],H[T]是积性函数,求详细证明的话将T和d展开为质因数次幂相乘的形式,考虑线性筛中枚举的质数与被筛数的性质即可
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e7 + ;
const int mod = 1e8 + ;
int cnt;
int h[maxn];
int pri[maxn];
int sum[maxn];
bool vis[maxn];
inline void Scan(int &x)
{
char c;
bool o = false;
while(!isdigit(c = getchar())) o = (c != '-') ? o : true;
x = c - '';
while(isdigit(c = getchar())) x = x * + c - '';
if(o) x = -x;
}
inline void Sieve()
{
h[] = ;
for(int i = ; i <= maxn; ++i)
{
if(!vis[i]) pri[++cnt] = i, h[i] = ((-(long long) i * i % mod) + mod + i) % mod;
for(int j = ; j <= cnt; ++j)
{
int s = pri[j];
long long k = (long long) i * s;
if(k > maxn) break;
vis[k] = true;
if(!(i % s))
{
h[k] = (long long) s * h[i] % mod;
break;
}
else h[k] = (long long) h[s] * h[i] % mod;
}
}
for(int i = ; i <= maxn; ++i) sum[i] = (sum[i - ] + h[i]) % mod;
}
inline int Sum(int n, int m)
{
return ((long long) n * (n + ) >> ) % mod * (((long long) m * (m + ) >> ) % mod) % mod;
}
inline int Mobius(int n, int m)
{
int res = , last = ;
if(n > m) swap(n, m);
for(int i = ; i <= n; i = last + )
{
last = min(n / (n / i), m / (m / i));
res = (res + (long long) Sum(n / i, m / i) * ((sum[last] - sum[i - ] + mod) % mod) % mod) % mod;
}
return res;
}
int main()
{
Sieve();
int n;
Scan(n);
int a, b;
while(n--)
{
Scan(a), Scan(b);
printf("%d\n", Mobius(a, b));
}
}
Crash的数字表格 BZOJ 2154 / jzptab BZOJ 2693的更多相关文章
- 【莫比乌斯反演】关于Mobius反演与lcm的一些关系与问题简化(BZOJ 2154 crash的数字表格&&BZOJ 2693 jzptab)
BZOJ 2154 crash的数字表格 Description 今天的数学课上,Crash小朋友学习了最小公倍数(Least Common Multiple).对于两个正整数a和b,LCM(a, b ...
- [bzoj 2693] jzptab & [bzoj 2154] Crash的数字表格 (莫比乌斯反演)
题目描述 TTT组数据,给出NNN,MMM,求∑x=1N∑y=1Mlim(x,y)\sum_{x=1}^N\sum_{y=1}^M lim(x,y)\newlinex=1∑Ny=1∑Mlim(x, ...
- 【BZOJ】【2154】Crash的数字表格
莫比乌斯反演 PoPoQQQ讲义第4题 题解:http://www.cnblogs.com/jianglangcaijin/archive/2013/11/27/3446169.html 感觉两次sq ...
- [BZOJ 2154]Crash的数字表格(莫比乌斯反演+数论分块)
[BZOJ 2154]Crash的数字表格(莫比乌斯反演+数论分块) 题面 求 \[\sum_{i=1}^{n} \sum_{j=1}^{m} \mathrm{lcm}(i,j)\] 分析 \[\su ...
- BZOJ 2154: Crash的数字表格 [莫比乌斯反演]
2154: Crash的数字表格 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 2924 Solved: 1091[Submit][Status][ ...
- 【BZOJ 2154】Crash的数字表格 (莫比乌斯+分块)
2154: Crash的数字表格 Description 今天的数学课上,Crash小朋友学习了最小公倍数(Least Common Multiple).对于两个正整数a和b,LCM(a, b)表示能 ...
- Bzoj 2154: Crash的数字表格(积性函数)
2154: Crash的数字表格 Time Limit: 20 Sec Memory Limit: 259 MB Description 今天的数学课上,Crash小朋友学习了最小公倍数(Least ...
- 2154: Crash的数字表格
2154: Crash的数字表格 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 3372 Solved: 1258[Submit][Status][ ...
- 洛谷 P1829 [国家集训队]Crash的数字表格 / JZPTAB 解题报告
[国家集训队]Crash的数字表格 / JZPTAB 题意 求\(\sum\limits_{i=1}^n\sum\limits_{j=1}^mlcm(i,j)\),\(n,m\le 10^7\) 鉴于 ...
随机推荐
- EXC_BAD_ACCESS调试
有时候,你会遇到由EXCBADACCESS造成崩溃. 这篇文件会告诉你什么是EXCBADACCESS,以及它产生的原因.我还会提供一些EXCBADACCESS错误的解决方案. 1. 什么是 EXCBA ...
- PostgreSQL学习(2)-- mvcc
1.PG事务隔离级别 在数据库中,并发的操作进行读写数据时,则会遇到脏读.不可重复读.幻读.串行化异常等问题. 数据库事务的特性: 原子性(Atomicity):事务作为一个整体被执行,包含在其中的对 ...
- Pycharm安装类库
比如安装requests 打开settings,选择Project 下面的Project Interpreter,点击pip,在弹出窗口里输入requests然后点击install 即可!
- MySQL中 IFNULL、NULLIF和ISNULL函数的用法
mysql 中 ifnull().nullif().isnull()函数的用法讲解: 一.IFNULL(expr1,expr2)用法: 假如expr1不为NULL,则 IFNULL() 的返回值为ex ...
- jsp内置对象及其方法
JSP中一共预先定义了9个这样的对象,分别为: request. response. session. application. out. pagecontext. con ...
- LeetCode(283)Move Zeroes
题目 Given an array nums, write a function to move all 0's to the end of it while maintaining the rela ...
- zoj 4054
#define ll long long ; int t; ll ans,tmp; char s[N]; int main() { scanf("%d",&t); whil ...
- meta-data
<meta-data android:name="string" android:resource="resource specification" ...
- 20188472 https://www.cnblogs.com/chenzg90826/
我是一名学计算机的大一学生,对学计算机比较感兴趣,但是对于计算机的了解程度还不够深,所以我在这方面还只是一个初学者.经过了一个学期对计算机和编程语言的学习,我觉得要真正的学好这门专业真的还要更努力.在 ...
- mysql 索引和查询优化
对于任何DBMS,索引都是进行优化的最主要的因素.对于少量的数据,没有合适的索引影响不是很大,但是,当随着数据量的增加,性能会急剧下降.如果对多列进行索引(组合索引),列的顺序非常重要,MySQL仅能 ...