[Luogu] 小凯的疑惑

https://www.luogu.org/problemnew/show/P3951

考场上打表找规律的我写出了这样一份代码(紧张到爆<已经爆>)

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define LL long long
#define gc getchar()

LL a, b, imp;

inline LL read() {
    LL x = 0;
    char c = gc;
    while(c < '0' || c > '9') c = gc;
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = gc;
    return x;
}

LL gcd(LL aa, LL bb) {
    return bb == 0 ? aa : gcd(bb, aa % bb);
}

int main() {
    a = read();
    b = read();
    if(a < b) swap(a, b);
    for(int i = b; ; i --) {
        if(gcd(i, b) == 1) {
            printf("%lld", i * a - b);
            return 0;
        }
    }

    return 0;
}

Answer = a * b - a - b;

猜你喜欢

转载自www.cnblogs.com/shandongs1/p/8982309.html