题意:

给定$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}})$ 求

  1. #include <bits/stdc++.h>
  2.  
  3. #define LL long long
  4. #define bit(x) (1<<(x))
  5. #define P 1000000007LL
  6.  
  7. using namespace std;
  8.  
  9. LL b,c;
  10. int a,num[];
  11.  
  12. LL calc(int n,int m) //1~n中和 m互质的数字个数
  13. {
  14. if(n==) return 0LL;
  15. int tmp = m;
  16. int tot = ;
  17. for(int i=;i*(LL)i<=(LL)m;i++)
  18. {
  19. if(tmp%i==)
  20. {
  21. while(tmp%i==) tmp/=i;
  22. num[++tot] = i;
  23. }
  24. }
  25. if(tmp>) num[++tot] = tmp;
  26. LL ans = ;
  27. for(int S=;S<(<<tot);S++)
  28. {
  29. int tmp = ,k = ;
  30. for(int i=;i<tot;i++) if(bit(i)&S) tmp *= num[i+], k = -k;
  31. ans += k * (n/tmp);
  32. }
  33. return ans % P;
  34. }
  35.  
  36. LL calc(int t)
  37. {
  38. if(t == ) return 0LL;
  39. LL ans = ;
  40. for(int d=;d*(LL)d<=(LL)a;d++)
  41. if(a%d==)
  42. {
  43. int tmpd = d;
  44. ans += (c / (a/tmpd)) % P * calc(t/tmpd,a/tmpd) % P;
  45. if(ans >= P) ans -= P;
  46. if(d*d != a)
  47. {
  48. tmpd = a/d;
  49. ans += (c / (a/tmpd)) % P * calc(t/tmpd,a/tmpd) % P;
  50. if(ans >= P) ans -= P;
  51. }
  52. }
  53. return ans;
  54. }
  55.  
  56. int main()
  57. {
  58. while(cin>>a>>b>>c)
  59. {
  60. LL ans = (b/a)%P * calc(a)%P + calc(b%(LL)a)%P;
  61. cout << ans % P << endl;
  62. }
  63. return ;
  64. }

counting the numbers的更多相关文章

  1. HDU 4349 Xiao Ming's Hope lucas定理

    Xiao Ming's Hope Time Limit:1000MS     Memory Limit:32768KB  Description Xiao Ming likes counting nu ...

  2. Lintcode: Partition Array

    Given an array "nums" of integers and an int "k", Partition the array (i.e move ...

  3. Hdu4349 Xiao Ming's Hope

    Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. Partition Array

    Given an array nums of integers and an int k, partition the array (i.e move the elements in "nu ...

  5. hdu 4349 Xiao Ming's Hope 规律

    Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. Weekly Contest 128

    1012. Complement of Base 10 Integer Every non-negative integer N has a binary representation.  For e ...

  7. HDU 4349——Xiao Ming's Hope——————【Lucas定理】

    Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. HDU 4349 Xiao Ming's Hope 找规律

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4349 Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/ ...

  9. lintcode刷题笔记(一)

    最近开始刷lintcode,记录下自己的答案,数字即为lintcode题目号,语言为python3,坚持日拱一卒吧... (一). 回文字符窜问题(Palindrome problem) 627. L ...

随机推荐

  1. iOS 倒计时NSTimer

    项目中可能会遇到有些倒计时的地方 比方 手机验证的时候,验证码一般都会有一个时间限制,此时在输入验证码的地方就须要展示一个倒计时 详细实现方式是使用了iOS 自带的 NSTimer 上代码 首先新建 ...

  2. ubuntu下调试ffmpeg程序出现undefined reference to pthread_once ,undefined reference to uncompress错误

    Ubuntu(版本16.04)下默认配置编译Ffmpeg(版本4.1.3configure 添加选项--enable-threads),将编译好的ffmpeg库添加到程序 中进行编译出现undefin ...

  3. MacBook Pro使用初体验之Mac快捷键汇总(持续更新中)

    我于近日购置了一台13寸的MacBook Pro高配,打算開始进行iOS开发的学习.Pro的配置情况例如以下: (1)OS X Yosemite ,版本号10.10.3 (2)Retina显示屏,13 ...

  4. 从S3中导入数据到Dynamodb

    本节如果你已经从Dynamodb中导出过数据,而且导出的文件以及被存入S3.文件内部结构会在Verify Data Export File 中描写叙述. 我们称之前导出数据的原始表为source ta ...

  5. iOS开发者必备:四款后端服务工具

    本文转载至 http://mobile.51cto.com/iphone-411917.htm 对于开发者来说,连接后端数据或许是一件特别痛苦的事情.但后端服务却能够帮助开发人员以更快的速度构建移动应 ...

  6. 【BZOJ3007】拯救小云公主 二分+几何+对偶图

    [BZOJ3007]拯救小云公主 Description     英雄又即将踏上拯救公主的道路……     这次的拯救目标是——爱和正义的小云公主.     英雄来到boss的洞穴门口,他一下子就懵了 ...

  7. 【BZOJ3566】[SHOI2014]概率充电器 期望+树形DP

    [BZOJ3566][SHOI2014]概率充电器 Description 著名的电子产品品牌 SHOI 刚刚发布了引领世界潮流的下一代电子产品——概率充电器:“采用全新纳米级加工技术,实现元件与导线 ...

  8. 【BZOJ2561】最小生成树 最小割

    [BZOJ2561]最小生成树 Description 给定一个边带正权的连通无向图G=(V,E),其中N=|V|,M=|E|,N个点从1到N依次编号,给定三个正整数u,v,和L (u≠v),假设现在 ...

  9. Collection of Boot Sector Formats for ISO 9660 Images

    http://bazaar.launchpad.net/~libburnia-team/libisofs/scdbackup/view/head:/doc/boot_sectors.txt Colle ...

  10. 浏览器访问配置完成的ftp服务器

    在浏览器的地址栏输入: ftp://testuser:testuser@192.168.10.4 testuser 是ftp的用户名和密码: 192.168.10.4 是ftp服务器的IP地址. 亲测 ...