题意:给定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 (莫比乌斯反演 + 分块)的更多相关文章

  1. hdu 5663 Hillan and the girl 莫比乌斯反演

    Hillan and the girl Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/O ...

  2. BZOJ 2301 Problem b(莫比乌斯反演+分块优化)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37166 题意:对于给出的n个询问,每次求有多少个数对(x,y),满 ...

  3. ACdream 1148(莫比乌斯反演+分块)

    传送门:GCD SUM 题意:给出N,M执行如下程序:long long  ans = 0,ansx = 0,ansy = 0;for(int i = 1; i <= N; i ++)   fo ...

  4. bzoj2301(莫比乌斯反演+分块)

    传送门:2301: [HAOI2011]Problem b 题意:对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y ...

  5. BZOJ 4407 于神之怒加强版 (莫比乌斯反演 + 分块)

    4407: 于神之怒加强版 Time Limit: 80 Sec  Memory Limit: 512 MBSubmit: 1067  Solved: 494[Submit][Status][Disc ...

  6. 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, ...

  7. bzoj2301 [HAOI2011]Problem b【莫比乌斯反演 分块】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2301 很好的一道题.首先把每个询问转化为4个子询问,最后的结果就是这四个子询问的记过加加减减 ...

  8. 2017ACM暑期多校联合训练 - Team 8 1002 HDU 6134 Battlestation Operational (数论 莫比乌斯反演)

    题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also k ...

  9. HDU 4675 GCD of Sequence(莫比乌斯反演 + 打表注意事项)题解

    题意: 给出\(M\)和\(a数组\),询问每一个\(d\in[1,M]\),有多少组数组满足:正好修改\(k\)个\(a\)数组里的数使得和原来不同,并且要\(\leq M\),并且\(gcd(a_ ...

随机推荐

  1. redis.conf配置详解(转)

    # redis 配置文件示例 # 当你需要为某个配置项指定内存大小的时候,必须要带上单位,# 通常的格式就是 1k 5gb 4m 等酱紫:## 1k => 1000 bytes# 1kb =&g ...

  2. go语言template包中模板语法总结

    package main; import ( "html/template" "os" "fmt" ) type Person struct ...

  3. sqlserver中对于特定数据字段定义特定的数据类型

    char和varchar:汉字占两个字节,英文.数字或字符占一个 比如: 性别:男   女 可以定义为:char(2)或者是varchar(2)    因为性别是中文,中文占两个字节 nchar和nv ...

  4. vue2.0后台系统

    参考网址: http://www.cnblogs.com/linxin/p/6509897.html

  5. Vue Create 创建一个新项目 命令行创建和视图创建

    Vue Create 创建一个新项目 命令行创建和视图创建 开始之前 你可以先 >>:cd desktop[将安装目录切换到桌面] >>:vue -V :Vue CLI 3.0 ...

  6. EmguCV Image类中的函数(二)使用MorphologyEx进行更多的变换

    MorphologyEx中所有的变换如下图所示 调用方法: Mat aaa = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.R ...

  7. android studio 安装过程

    下载 安装版本:3.0.1 下载地址:https://pan.baidu.com/s/1Uq6QSZXpmWUiBW6K-tRqKw 密码:zbtb 安装 双击安装包进行安装,选择安装位置,安装完成打 ...

  8. PopupWindow与Edittext结合使用所遇到的坑

    PopupWindow与Edittext结合使用一起实现目的:既可以编辑输入想要的内容,还可以通过下拉列表来实现内容的选择. 我就是这样的一个目的,结果很简单的目的却遇到了很大的坑,下面我将把我遇到的 ...

  9. Java 内存模型、GC原理及算法

    Java 内存模型.GC原理:https://blog.csdn.net/ithomer/article/details/6252552 GC算法:https://www.cnblogs.com/sm ...

  10. Scrapy-Redis分布式策略

    Scrapy-Redis分布式策略 原理图: 假设有四台电脑:Windows 10.Mac OS X.Ubuntu 16.04.CentOS 7.2,任意一台电脑都可以作为 Master端 或 Sla ...