洛谷-P1029 [NOIP2001 普及组] 最大公约数和最小公倍数问题

洛谷-P1029 [NOIP2001 普及组] 最大公约数和最小公倍数问题

原题链接:https://www.luogu.com.cn/problem/P1029


题目描述

输入两个正整数(x_0, y_0),求出满足下列条件的 (P, Q) 的个数:

  1. (P,Q) 是正整数。
  2. 要求 (P, Q)(x_0) 为最大公约数,以 (y_0) 为最小公倍数。

试求:满足条件的所有可能的 (P, Q) 的个数。

输入格式

一行两个正整数 (x_0, y_0)

输出格式

一行一个数,表示求出满足条件的 (P, Q) 的个数。

输入输出样例

输入 #1

3 60

输出 #1

4

说明/提示

P,Q 有 (4) 种:

  1. (3, 60)
  2. (15, 12)
  3. (12, 15)
  4. (60, 3)

对于 (100\%) 的数据,(2 le x_0, y_0 le {10}^5)

【题目来源】

NOIP 2001 普及组第二题

C++代码

#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
    int x, y, i, j, t, ans=0;
    scanf("%d%d", &x, &y);
    for (i=x; i<=y; ++i) {
        if (x * y % i == 0)
            j = x * y / i;
            t = __gcd(i, j);
            if (t==x && i*j*1.0/t==y)
                ++ans;
        }
    printf("%d
", ans);
    return 0;
}
原文地址:https://www.cnblogs.com/yuzec/p/14214740.html