페이지

12779번: 상품 is 뭔들

https://www.acmicpc.net/problem/12779


$O(\lg(\max(a,b)))$

#include<cstdio>
#include<cmath>
typedef long long ll;
ll a, b, n, g;
ll gcd(ll x, ll y) { return y ? gcd(y, x%y) : x; }
int main() {
    scanf("%lld%lld", &a, &b);
    n = (ll)sqrt(b) - (ll)sqrt(a);
    g = gcd(n, b - a);
    n ? printf("%lld/%lld", n / g, (b - a) / g) : puts("0");
    return 0;
}

댓글 없음 :

댓글 쓰기