题意:

给定$a,b,c$ ,求解满足 $1 \leq m \leq b, 1 \leq n \leq c, a | mn$ 的 $(m,n)$ 数对个数。

$a \leq INTMAX$, $b \leq LONGLONGMAX$

解法

原问题相当于求解 $mn \  mod \  a \equiv 0$ 的数对个数。

$(m \  mod \ a) n \ mod \ a \equiv 0$

这样$m$ ,实际有效的是 $m \ mod \ a$。

这样我们可以将原问题中的 $m$ 分为 $[\frac{b}{a}]$ 段 $m \equiv 1\  to \  a (mod \ a)$,

与一段 $m \equiv 1 \ to(b \mod \ a) (mod \ a)$

考虑求解 $m ∈ [1,t]$ 的 $(m,n)$ 数对个数 $F(t)$。

这样有$$ans = [b/a]F(a) + F(b \ mod \ a)$$

$$F(t) = \sum_{m=1}^t { [\frac{c}{ \frac{a}{(a,m)} }] }$$

记 $d = (m,a)$

$$F(t) = \sum_{d|a}{ [\frac{c}{ \frac{a}{d} }] (the\ cnt\ of\ m\ that (m,a) = d) }$$

$$F(t) = \sum_{d|a}{ [\frac{c}{ \frac{a}{d} }] (the\ cnt\ of\ m\ that (\frac{m}{d},\frac{a}{d}) = 1) }$$

$$F(t) = \sum_{d|a}{ [\frac{c}{ \frac{a}{d} }] (the\ cnt\ of\ i\ that (i,\frac{a}{d}) = 1 and i \leq [\frac{t}{d}]) }$$

后者可以通过容斥$O(\sqrt {\frac{a}{d}})$ 求

#include <bits/stdc++.h>

#define LL long long
#define bit(x) (1<<(x))
#define P 1000000007LL using namespace std; LL b,c;
int a,num[]; LL calc(int n,int m) //1~n中和 m互质的数字个数
{
if(n==) return 0LL;
int tmp = m;
int tot = ;
for(int i=;i*(LL)i<=(LL)m;i++)
{
if(tmp%i==)
{
while(tmp%i==) tmp/=i;
num[++tot] = i;
}
}
if(tmp>) num[++tot] = tmp;
LL ans = ;
for(int S=;S<(<<tot);S++)
{
int tmp = ,k = ;
for(int i=;i<tot;i++) if(bit(i)&S) tmp *= num[i+], k = -k;
ans += k * (n/tmp);
}
return ans % P;
} LL calc(int t)
{
if(t == ) return 0LL;
LL ans = ;
for(int d=;d*(LL)d<=(LL)a;d++)
if(a%d==)
{
int tmpd = d;
ans += (c / (a/tmpd)) % P * calc(t/tmpd,a/tmpd) % P;
if(ans >= P) ans -= P;
if(d*d != a)
{
tmpd = a/d;
ans += (c / (a/tmpd)) % P * calc(t/tmpd,a/tmpd) % P;
if(ans >= P) ans -= P;
}
}
return ans;
} int main()
{
while(cin>>a>>b>>c)
{
LL ans = (b/a)%P * calc(a)%P + calc(b%(LL)a)%P;
cout << ans % P << endl;
}
return ;
}

最新文章

  1. eCharts 数据转换json
  2. Cannot instantiate the type AppiumDriver
  3. kali 更改root密码
  4. hdu5878(枚举,打表)
  5. 【转】Android Studio系列教程一--下载与安装
  6. 【转】Android 使用Scroller实现绚丽的ListView左右滑动删除Item效果
  7. Linux流量监控工具使用总结 - iftop
  8. 一起看看2016中国第三届CSS开发者大会有哪些大咖演讲
  9. S5PV210中断处理
  10. linux下boost的安装与编译
  11. OOP的基本原则
  12. php密码对称encrypt加密
  13. 解决Git Revert操作后再次Merge代码被冲掉的问题
  14. maven 本地仓库无法更新到最新版本的jar包
  15. HAOI2016 简要题解
  16. java虚拟机的内存模型
  17. DevC++出现[Error] ld returned 1 exit status,如何解决才好呢?
  18. ;,&amp;,&amp;&amp;,shell,区别
  19. C语言实现输出杨辉三角
  20. C语言学习记录_2019.02.05

热门文章

  1. 定义自己的代码风格CheckStyle简单使用
  2. python(17)- 迭代器和生成器及应用
  3. mysql 查看当前连接数
  4. 利用泛型和反射,管理配置文件,把Model转换成数据行,并把数据行转换成Model
  5. 使用EA生成多层次的代码框架
  6. unittest相关文档
  7. “懒”也要有境地---大部分程序猿都在的地方,再不来就out了。
  8. cocos2d-x lua 中使用protobuf并对http进行处理
  9. 【BZOJ4407】于神之怒加强版 莫比乌斯反演
  10. jni native macOS