NOIP 模拟赛

NOIP 模拟赛

NOIP 模拟赛

思路:求 n , m 的 gcd,然后用 n , m 分别除以 gcd;若 n 或 m 为偶数,则输出 1/2.

  特别的,当 n = m = 1 时,应输出 1/1

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long LL;
LL n, m;

LL gcd(LL x, LL y) {
    return y == 0 ? x : gcd(y, x % y);
}

int main() {
    freopen("line.in","r",stdin);
    freopen("line.out","w",stdout);
    cin >> n >> m;
    if (n == m && m == 1) return printf("1/1\n"), 0;
    LL tmp = gcd(n, m);
    n /= tmp; m /= tmp;
    if (!(n & 1) || !(m & 1)) return printf("1/2\n"), 0;
    
    fclose(stdin); fclose(stdout);
    return 0;
}
考场代码

相关文章: