11618 - pB - Birthday Party
raw download clone
C
views 22
,
size 712 b
#include <stdio.h>

unsigned long long gcd(unsigned long long a, unsigned long long b);
unsigned long long lcm(unsigned long long a, unsigned long long b);

int main(void)
{
    int t;
    unsigned long long n, r, b, y, lcmc, lcmall, q;

    scanf("%d", &t);
    for(int i=1; i<=t; i++)
    {
        scanf("%llu%llu%llu%llu", &n, &r, &b, &y);
        printf("%llu\n", n / lcm(lcm(gcd(r, n), gcd(b, n)), gcd(y, n)));
    }

    return 0;
}

unsigned long long gcd(unsigned long long a, unsigned long long b)
{
    if(b)
        while((a %= b) && (b %= a));
    return a + b;
}

unsigned long long lcm(unsigned long long a, unsigned long long b)
{
    return a * (b / gcd(a, b));
}
close fullscreen
Login or Register to edit or fork this paste. It's free.