数论,CF 992B - Nastya Studies Informatics

一、题目

1、题目描述

2、输入输出

2.1输入

2.2输出

3、原题链接

992B - Nastya Studies Informatics


二、解题报告

1、思路分析

a * b = x * y

a' * b' * x ^ 2 = x * y

=>

a‘ * b' = y / x,其中a'和b'互质,x整除y

那么对于x不整除y的情况直接输出0

否则,我们看y / x能拆出多少pair,即分解因数即可

2、复杂度

时间复杂度: O(\sqrt{\frac{y}{x}})空间复杂度:O(1)

3、代码详解

 ​
#include <bits/stdc++.h>
using i64 = long long;
using i128 = __int128;
using PII = std::pair<int, int>;
using PIII = std::pair<int, PII>;
const int inf = 1e9 + 7, P = 1e9 + 7;

/*
    a * b = x * y
    a' * b' * x^2 = x * y
    a' * b' = y / x
*/


void solve() {
    int l, r, x, y;
    std::cin >> l >> r >> x >> y;
    int res = 0;
    if (y % x == 0)
        for (int i = 1, ed = y / x; i * i <= ed; ++ i) 
            if (ed % i == 0 && std::__gcd(i, ed / i) == 1) 
                if (l <= i * x && i * x <= r && l <= ed / i * x && ed / i * x <= r)
                    res += 1 + (i != ed / i);
    
    std::cout << res;
}


int main(int argc, char** argv) {
    std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
    int _ = 1;
    // std::cin >> _;
    while (_ --)
        solve();
    return 0;
}

相关推荐

  1. B - Array Craft(cf960)

    2024-07-12 16:56:01       18 阅读
  2. CF1902 B Getting Points 题解

    2024-07-12 16:56:01       64 阅读
  3. CF1898B Milena and Admirer(贪心)

    2024-07-12 16:56:01       59 阅读
  4. CF97B Superset 题解 分治

    2024-07-12 16:56:01       53 阅读
  5. CF1709B - Also Try Minecraft 题解

    2024-07-12 16:56:01       28 阅读
  6. cf240-B-Mashmokh and ACM DP

    2024-07-12 16:56:01       24 阅读
  7. CF 1901B Chip and Ribbon 学习笔记

    2024-07-12 16:56:01       59 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-12 16:56:01       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-12 16:56:01       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-12 16:56:01       57 阅读
  4. Python语言-面向对象

    2024-07-12 16:56:01       68 阅读

热门阅读

  1. vue3+ts 使用WebSocket

    2024-07-12 16:56:01       23 阅读
  2. Chubby VS Zookeeper

    2024-07-12 16:56:01       22 阅读
  3. 需求实现:字数限制500字

    2024-07-12 16:56:01       19 阅读
  4. 安全开发基础篇-数据溢出

    2024-07-12 16:56:01       25 阅读
  5. MySQL 用like “%x“,索引就一定会失效吗?

    2024-07-12 16:56:01       22 阅读
  6. Windows CMD 命令汇总表

    2024-07-12 16:56:01       17 阅读
  7. Spring Boot应用启动慢的原因分析及优化方法

    2024-07-12 16:56:01       22 阅读
  8. python工作中遇到的坑

    2024-07-12 16:56:01       23 阅读
  9. 算法面试题_字节

    2024-07-12 16:56:01       26 阅读
  10. CHD安装

    2024-07-12 16:56:01       22 阅读
  11. 开源项目有哪些机遇和挑战?

    2024-07-12 16:56:01       21 阅读