[idle] Trima sreshtu edin -- 4:7

  • From: Ivaylo Riskov <ivaylo_riskov@xxxxxxx>
  • To: idle@xxxxxxxxxxxxx
  • Date: Sat, 26 Apr 2003 15:44:20 +0300

Ha, ha. Kakwo stana momcheta?
Eto wi A i E. Gledajte si gi i im se kefete. :)
Btw, Ludo, nali kaza che taq s Gopher-a ste q reshili?

Pozdrawi!
-- 
Ivaylo Riskov <ivaylo_riskov@xxxxxxx>

"If it happens, it must be possible."
#include <stdio.h>

int prime[30];
int factors[30];
int ptr = 0; 

void Eratosten() {
    int sieve[100];
    int i, j;

    for (i = 0; i < 100; i++)
        sieve[i] = 0;

    for (i = 2; i < 100; i++)
        if (!sieve[i]) {
            prime[ptr++] = i;
            for (j = i; j < 100; j += i)
                sieve[j] = 1;
        }
}

int main() {
        int n, d, t;
        int i, j;
        long long c;
        
        Eratosten();
        while (1) {
                scanf("%i %i", &n, &d);
                if (!n && !d)
                        break;
                if (d < 0)
                        d *= -1;
                for (i = 0; i < 30; i++)
                        factors[i] = 0;

                for (i = 2; i <= n; i++) 
                        for (t = i, j = 0; t > 1 && j < ptr; j++)
                                while (t%prime[j] == 0)
                                        t /= prime[j], factors[j]++;
                
                for (j = 0; d > 1 && j <ptr; j++)
                        while (d%prime[j] == 0)
                                d /= prime[j], factors[j]--;
                
                if (d > 1) {
                        printf("0\n");
                        continue;
                }
                c = 1;
                
                for (i = 0; i < ptr; i++)
                        if (factors[i] < 0) {
                                c = 0;
                                break;
                        }
                        else
                                c *= factors[i] + 1;

                printf("%Li\n", c);
        }
        return 0;
}

#include <stdio.h>
#include <math.h>

int cmp(double x, double y) {
        if (x - y > 1e-8)
                return 1;
        if (y - x > 1e-8)
                return -1;
        return 0;
}

int main() {
        int n1, n2;
        int in_d1, in_d2;
        double D, L, x1, y1, x2, y2;
        double t;
        double w, sw;
        
        while (scanf("%lf %lf %lf %lf %lf %lf", &D, &L, &x1, &y1, &x2, &y2) == 
6) {
                if (cmp(y1, y2) > 0) {
                        t = x1; x1 = x2; x2 = t;
                        t = y1; y1 = y2; y2 = t;
                }

                n1 = y1/D;
                if (cmp(y1, 0.0) < 0)
                        n1--;
                if (cmp(y1, n1*D - L) >= 0 && cmp(y1, n1*D + L) <= 0)
                        in_d1 = 1;
                else {
                        n1++;
                        if (cmp(y1, n1*D - L) >= 0 && cmp(y1, n1*D + L) <= 0)
                                in_d1 = 1;
                        else
                                in_d1 = 0;
                }

                n2 = y2/D + 1;
                if (cmp(y2, 0.0) < 0)
                        n2--;
                if (cmp(y2, n2*D - L) >= 0 && cmp(y2, n2*D + L) <= 0)
                        in_d2 = 1;
                else {
                        n2--;
                        if (cmp(y2, n2*D - L) >= 0 && cmp(y2, n2*D + L) <= 0)
                                in_d2 = 1;
                        else
                                in_d2 = 0;
                }

                // both are in the same ditch
                if (in_d1 && in_d2 && n1 == n2) {
                        w = fabs(x1 - x2);
                        if (cmp(y1 - (n1*D - L) + y2 - (n2*D - L),
                                        (n1*D + L) - y1 + (n2*D + L) - y2) > 0)
                                sw = (n1*D + L) - y1 + (n2*D + L) - y2;
                        else
                                sw = y1 - (n1*D - L) + y2 - (n2*D - L);
                        t = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
                        if (cmp(t, sw) < 0)
                                sw = t, w = 0.0;
printf("The gopher has to swim %.2lf meters and walk %.2lf meters.\n", sw, w);
                        continue;
                }

                sw = 0.0;
                if (in_d1) {
                        sw += n1*D + L - y1; n1++;
                }
                if (in_d2) {
                        sw += y2 - n2*D + L; n2--;
                }
                sw += 2.0*(n2 - n1 + 1)*L;
                t = fabs(y2 - y1) - sw;
                w = x2 - x1;
                w = sqrt(t*t + w*w);
                
printf("The gopher has to swim %.2lf meters and walk %.2lf meters.\n", sw, w);
        }
        return 0;
}

Other related posts:

  • » [idle] Trima sreshtu edin -- 4:7