洛谷P1072 Hankson 的趣味题(数学)
2024-09-04 12:29:51
题意
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;
}
最新文章
- 深入理解this机制系列第三篇——箭头函数
- AspectJ的基本使用
- 多媒体音频(audio)
- [css] vertical-align和line-height
- jenkins参数化构建过程
- aspcms中if判断语句的运用
- HW7.3
- error on line 1 at column 6: XML declaration allowed only at the start of the document
- 2015必须要看的APP源码
- 内功心法 -- Java标记接口
- iOS开发 - 适配Https的野路子
- python 基础安装使用
- Netflix Hystrix - 快速入门
- C语言函数嵌套调用作业
- Centos 7 Linux系统修改网卡名称为ethx
- PeopleSoft如何查找jar包冲突
- Open Distro for Elasticsearch – How Different Is It?
- 洛谷P2868 [USACO07DEC]观光奶牛Sightseeing Cows(01分数规划)
- Java中list如何利用遍历进行删除操作
- BootStrap Table显示行号,并且分页后依然递增
热门文章
- iOS 进阶---推送通知之本地通知
- Web App三年将取代原生App?
- esp32 blink实验
- Django之ContentTypes
- 命令行下class redis not found 解决
- SQL数据库正在恢复 查看进度
- sencha touch extend 单继承 和 mixins 实现多继承
- sencha touch textarea 手机上不显示滚动条,且不能滚动
- IDEA里运行代码时出现Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger的解决办法(图文详解)
- 【Javascript】 DOM节点