HDU 5663 Hillan and the girl (莫比乌斯反演 + 分块)
题意:给定n,m,求
,其中F(x)=0,,如果x是完全平方数,否则是1。
析:

由于按照题意的F,不好筛选,所以我们反过来,F(x),x是平方数,就是1,否则是0。
这个是可以预处理出来的,可以用筛选。
这一部分,可以分块来做,所以时间复杂度就降下来了。
代码如下:
#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 = 1e7 + 5;
const int maxm = 2e4 + 10;
const LL mod = 100000007;
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;
} bool vis[maxn];
int prime[maxn], mu[maxn];
int sum[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(i nt 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 t = sqrt(maxn + 0.5);
for(int i = 1; i <= t; ++i){
int x = i * i;
for(int j = x, k = 1; j < maxn; j += x, ++k)
sum[j] += mu[k];
}
for(int i = 1; i < maxn; ++i) sum[i] += sum[i-1];
} int main(){
Moblus();
int T; scanf("%d", &T);
while(T--){
scanf("%d %d", &n, &m);
if(n > m) swap(n, m);
LL ans = (LL)n * m;
for(int i = 1, det; i <= n; i = det + 1){
det = min(n/(n/i), m/(m/i));
ans -= (LL)(sum[det]-sum[i-1]) * (m/i) * (n/i);
}
printf("%I64d\n", ans);
}
return 0;
}
HDU 5663 Hillan and the girl (莫比乌斯反演 + 分块)的更多相关文章
- hdu 5663 Hillan and the girl 莫比乌斯反演
Hillan and the girl Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/O ...
- BZOJ 2301 Problem b(莫比乌斯反演+分块优化)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37166 题意:对于给出的n个询问,每次求有多少个数对(x,y),满 ...
- ACdream 1148(莫比乌斯反演+分块)
传送门:GCD SUM 题意:给出N,M执行如下程序:long long ans = 0,ansx = 0,ansy = 0;for(int i = 1; i <= N; i ++) fo ...
- bzoj2301(莫比乌斯反演+分块)
传送门:2301: [HAOI2011]Problem b 题意:对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y ...
- BZOJ 4407 于神之怒加强版 (莫比乌斯反演 + 分块)
4407: 于神之怒加强版 Time Limit: 80 Sec Memory Limit: 512 MBSubmit: 1067 Solved: 494[Submit][Status][Disc ...
- bzoj 2301 [HAOI2011]Problem b(莫比乌斯反演+分块优化)
题意:对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. 1≤n≤50000,1≤a≤b≤50000, ...
- bzoj2301 [HAOI2011]Problem b【莫比乌斯反演 分块】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2301 很好的一道题.首先把每个询问转化为4个子询问,最后的结果就是这四个子询问的记过加加减减 ...
- 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)
题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...
- HDU 4675 GCD of Sequence(莫比乌斯反演 + 打表注意事项)题解
题意: 给出\(M\)和\(a数组\),询问每一个\(d\in[1,M]\),有多少组数组满足:正好修改\(k\)个\(a\)数组里的数使得和原来不同,并且要\(\leq M\),并且\(gcd(a_ ...
随机推荐
- [leetcode]210. Course Schedule II课程表II
There are a total of n courses you have to take, labeled from 0 to n-1. Some courses may have prereq ...
- java 线程Thread 技术--1.5 Future与Callable
Callable: 从官方文档说起: 通过实现callable 的called 方法可以使一个任务可以返回一个结果以及可能抛出一个异常: callable 与runnable 是相似的,可以被其他线程 ...
- 用Python监听鼠标和键盘事件
PyHook是一个基于Python的“钩子”库,主要用于监听当前电脑上鼠标和键盘的事件.这个库依赖于另一个Python库PyWin32,如同名字所显示的,PyWin32只能运行在Windows平台,所 ...
- pycharm 出现Process finished with exit code 0 或 Process finished with exit code -1
Process finished with exit code 0 意味着你的程序正常执行完毕并退出. 可以科普一下exit code,在大部分编程语言中都适用: exit code 0 表示程序执行 ...
- u-boot之ARM920T的start.S分析
cpu/arm920t/start.S程序步骤大致有以下几个 1.设置中断向量表 2.设置CPU模式为SVC32 mode并且关闭IRQ与FIQ中断 3.关闭看门狗 4.屏蔽所有中断 5.判断程序是否 ...
- qRT-PCR 注意事项
师姐呕心沥血整理的 qRT-PCR 注意事项 关键词: qRT-PCR 注意事项2017-07-17 10:17 来源:生物学霸 点击次数:1257 大家都在说 qRT-PCR 实验原理.引物设计.结 ...
- HDOJ2586 How far away ?
一道LCA模板 原题链接 \(LCA\)模板题,不解释. 倍增版 #include<cstdio> #include<cmath> #include<cstring> ...
- egg 为企业级框架和应用而生, 阿里出品
https://eggjs.org/zh-cn/intro/ egg 是什么? egg 为企业级框架和应用而生,我们希望由 egg 孕育出更多上层框架,帮助开发团队和开发人员降低开发和维护成本. 设计 ...
- MySQL学习笔记-事务相关话题
事务机制 事务(Transaction)是数据库区别于文件系统的重要特性之一.事务会把数据库从一种一致状态转换为另一个种一致状态.在数据库提交工作时,可以确保其要么所有修改都已经保存了,要么所有修改都 ...
- $(QTDIR);$(QTDIR)\include\QtCore;$(QTDIR)\include;
$(QTDIR); 在系统环境变量中定义即可 vs属性中设置头文件路径