题意

题目链接

Sol

充满套路的数学题。。

如果你学过莫比乌斯反演的话不难得到两个等式

\[gcd(\frac{x}{a_1}, \frac{a_0}{a_1}) = 1
\]

\[gcd(\frac{b_1}{b_0}, \frac{b_1}{x}) = 1
\]

然后枚举\(b_1\)的约数就做完了。。

// luogu-judger-enable-o2
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN = 1e6;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int T, a0, a1, b0, b1, ans;
int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
void check(int x) {
if(x % a1) return ;
ans += (gcd(x / a1, a0 / a1) == 1 && gcd(b1 / b0, b1 / x) == 1);
}
int main() {
T = read();
while(T--) {
a0 = read(), a1 = read(), b0 = read(), b1 = read(); ans = 0;
for(int x = 1; x * x <= b1; x++) {
if(b1 % x == 0) {
check(x);
if(b1 != x) check(b1 / x);
}
}
cout << ans << endl;
}
return 0;
}

最新文章

  1. 深入理解this机制系列第三篇——箭头函数
  2. AspectJ的基本使用
  3. 多媒体音频(audio)
  4. [css] vertical-align和line-height
  5. jenkins参数化构建过程
  6. aspcms中if判断语句的运用
  7. HW7.3
  8. error on line 1 at column 6: XML declaration allowed only at the start of the document
  9. 2015必须要看的APP源码
  10. 内功心法 -- Java标记接口
  11. iOS开发 - 适配Https的野路子
  12. python 基础安装使用
  13. Netflix Hystrix - 快速入门
  14. C语言函数嵌套调用作业
  15. Centos 7 Linux系统修改网卡名称为ethx
  16. PeopleSoft如何查找jar包冲突
  17. Open Distro for Elasticsearch – How Different Is It?
  18. 洛谷P2868 [USACO07DEC]观光奶牛Sightseeing Cows(01分数规划)
  19. Java中list如何利用遍历进行删除操作
  20. BootStrap Table显示行号,并且分页后依然递增

热门文章

  1. iOS 进阶---推送通知之本地通知
  2. Web App三年将取代原生App?
  3. esp32 blink实验
  4. Django之ContentTypes
  5. 命令行下class redis not found 解决
  6. SQL数据库正在恢复 查看进度
  7. sencha touch extend 单继承 和 mixins 实现多继承
  8. sencha touch textarea 手机上不显示滚动条,且不能滚动
  9. IDEA里运行代码时出现Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger的解决办法(图文详解)
  10. 【Javascript】 DOM节点