题链:

http://www.lydsy.com/JudgeOnline/problem.php?id=2301

题解:

莫比乌斯反演,入门题。

类似●HDU 1695 GCD

只是多了一个下界,(另外本题把(a,b)和(b,a)看成两种不同的答案)

把问题拆成四个就好了。

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#define MAXN 100500
using namespace std;
int mu[MAXN],pmu[MAXN];
void Mobius_Sieve(){
static bool np[MAXN]; mu[1]=1; pmu[1]=1;
static int prime[MAXN],pnt;
for(int i=2;i<=100000;i++){
if(!np[i]) prime[++pnt]=i,mu[i]=-1;
pmu[i]=pmu[i-1]+mu[i];
for(int j=1;j<=pnt&&i<=100000/prime[j];j++){
np[prime[j]*i]=1;
if(i%prime[j]) mu[i*prime[j]]=-mu[i];
else mu[i*prime[j]]=0;
if(i%prime[j]==0) break;
}
}
}
long long work(int n,int m){
long long ret=0,tmp;
for(int i=1,last;i<=min(n,m);i=last+1){
last=min(n/(n/i),m/(m/i));
tmp=1ll*(pmu[last]-pmu[i-1])*(n/i)*(m/i);
ret+=tmp;
}
return ret;
}
long long ans(int n,int m,int k){
return work(n/k,m/k)/*-work(min(n,m)/k,min(n,m)/k)/2*/;
}
int main(){
Mobius_Sieve();
int a,b,c,d,k,Case; long long ANS;
scanf("%d",&Case);
for(int i=1;i<=Case;i++){
scanf("%d%d%d%d%d",&a,&b,&c,&d,&k);
if(k==0){printf("0\n"); continue;}
//printf("%lld\n",ans(b,d,k));
ANS=ans(b,d,k)-ans(a-1,d,k)-ans(b,c-1,k)+ans(a-1,c-1,k);
/*
int dn=max(a,c),up=min(b,d);
long long _ANS=ans(up,up,k)-ans(dn-1,up,k)-ans(up,dn-1,k)+ans(dn-1,dn-1,k);
printf("不重复:%lld\n",ANS-_ANS/2);
*/
printf("%lld\n",ANS);
}
return 0;
}

  

●2301 [HAOI2011] Problem b的更多相关文章

  1. bzoj 2301: [HAOI2011]Problem b

    2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MB Submit: 3757 Solved: 1671 [Submit] ...

  2. BZOJ 2301: [HAOI2011]Problem b 莫比乌斯反演

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 1007  Solved: 415[Submit][ ...

  3. 2301: [HAOI2011]Problem b

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4164  Solved: 1888[Submit] ...

  4. BZOJ 2301: [HAOI2011]Problem b( 数论 )

    和POI某道题是一样的...  http://www.cnblogs.com/JSZX11556/p/4686674.html 只需要二维差分一下就行了. 时间复杂度O(MAXN + N^1.5) - ...

  5. 2301: [HAOI2011]Problem b ( 分块+莫比乌斯反演+容斥)

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 6015  Solved: 2741[Submit] ...

  6. BZOJ 2301 [HAOI2011]Problem b (分块 + 莫比乌斯反演)

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 6519  Solved: 3026[Submit] ...

  7. BZOJ 2301: [HAOI2011]Problem b (莫比乌斯反演)

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 436  Solved: 187[Submit][S ...

  8. Bzoj 2301: [HAOI2011]Problem b(莫比乌斯反演+除法分块)

    2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MB Description 对于给出的n个询问,每次求有多少个数对(x, ...

  9. 【BZOJ】2301: [HAOI2011]Problem b(莫比乌斯+分块)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2301 和这题不是差不多的嘛--[BZOJ]1101: [POI2007]Zap(莫比乌斯+分块) 唯 ...

随机推荐

  1. 从0开始的LeetCode生活—461-Hamming Distance(汉明距离)

    题目: The Hamming distance between two integers is the number of positions at which the corresponding ...

  2. django搭建web (二) urls.py

    URL模式: 在app下的urls.py中 urlpatterns=[ url(正则表达式,view函数,参数,别名,前缀)] urlpatterns=[ url(r'^hello/$',hello. ...

  3. prototype 原型链

    // 方法1 var aa=function(){ function bb(){ this.name="1111"; console.log(this.name) }; bb.pr ...

  4. 服务器数据恢复_Linux网站服务器故障数据恢复案例

    [数据恢复故障描述] 一台linux网站服务器,DELL R200,管理约50个左右网站,使用一块SATA 160GB硬盘.正常使用中突然宕机,尝试再次启动失败,将硬盘拆下检测时发现存在约100个坏扇 ...

  5. Python脚本自动提取和替换代码中的中文

    # -*- coding: utf-8 -*- import os import os.path import re import sys reload(sys) sys.setdefaultenco ...

  6. Python——cmd调用(os.system阻塞处理)

    os.system(返回值为0,1,2) 0:成功 1:失败 2:错误 os.system默认阻塞当前程序执行,在cmd命令前加入start可不阻塞当前程序执行. 例如: import os os.s ...

  7. Python3 re模块(正则表达式)

    一:什么是正则? 正则就是用一些具有特殊含义的符号组合到一起(称为正则表达式)来描述字符或者字符串的方法.或者说:正则就是用来描述一类事物的规则. (在Python中)它内嵌在Python中,并通过r ...

  8. leetcode算法: Find All Duplicates in an Array

    Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others ...

  9. lambda匿名函数透析

    lambda匿名函数透析 目录 1       匿名函数的作用... 1 2       匿名函数的格式... 1 3       匿名函数实例代码... 3   1         匿名函数的作用 ...

  10. hive:数据库“行专列”操作---使用collect_set/collect_list/collect_all & row_number()over(partition by 分组字段 [order by 排序字段])

    方案一:请参考<数据库“行专列”操作---使用row_number()over(partition by 分组字段 [order by 排序字段])>,该方案是sqlserver,orac ...