只有#6过了,其他点都re了,帮忙看下吧

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

daydream1ng @ 2024-12-13 22:37:18

#include <bits/stdc++.h>
using namespace std;

int fun (int a, int b){
    if (a < b) swap(a, b);
    if (b == 0) return a;
    fun (b, a % b);
}

int main ()
{
    int x, y; cin >> x >> y;
    int cnt = 0;
    for (int p = 1; p <= x * y; p++){
        int q = x * y / p;
        if (fun (p, q) == x && p * q / fun (p, q) == y) 
            cnt++;
    }
    cout << cnt << endl;
}

|