题意:

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

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. Apcahe Shiro学习笔记(二):通过JDBC进行权限控制

    一.概述: 官方对Realm(领域)的描述:https://www.infoq.com/articles/apache-shiro 其功能本质上是一个安全特定的DAO,用于链接数据持久层(任何形式的都 ...

  2. PHP 7.1.5编译安装

    1. 安装基础组件 yum install -y libxml2 libxml2-devel bzip2 bzip2-devel curl-devel libjpeg libjpeg-devel li ...

  3. beyond compare添加右键快捷方式

    如果安装beyond compare后,右键不能出现比较选项,可以通过设置 beyond compare完成. 选择 工具->选项,在资源管理器整合下面,有一个在资源管理器关联菜单中显示beyo ...

  4. SQL Cursor生命周期

      阅读导航 1 Cursor Step 1.1 Create cursor 1.2 Parse statement 1.3 descript and define 1.4 Bind variable ...

  5. centos6.4中文输入法安装和切换(转载)

    1.用root登录,或者切换到root账户(su root): 2.yum install "@Chinese Support"; 3.exit: 4.System→prefere ...

  6. 代写GIS系统

    代写GIS系统,熟悉arcgis,leaflet ,百度地图等api.可以提供系统代写,技术咨询等

  7. yii框架之gii创建数据表相应的model类

    一.首先是在数据库中建立project须要的表: 二.然后,配置相应文件: 在project文件夹下yiiProject\protected\config\main.php.在50行定义了db应用组件 ...

  8. 设置netbeans文件编码格式

    在项目ecmall上右键 选择属性,然后在项目属性里设置

  9. WF中的Bookmark

    最近在学习WF, 把自己的一些学习心得放上来 Bookmark允许你以事件驱动的方式与一个Workflow内的Activity进行交互. 如果把启动一个workflow比做开始读一本书, 在Workf ...

  10. 配置tomcat,使访问项目时候无项目名

    首先在盘符下新建一个文件夹(web),该文件夹存贮运行的项目用. 然后编辑config文件夹下的server.xml文件: 在<Host>标签中添加配置: <Context path ...