Cod sursa(job #185632)

Utilizator firewizardLucian Dobre firewizard Data 25 aprilie 2008 18:47:17
Problema Pascal Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <stdio.h>
int n, d, p[69], x, k, count; 
void copy_paste()
{ 
     x = n - k;
     while (x % 2 == 0) 
           x /= 2, p[2]++;
     while (x % 3 == 0)
           x /= 3, p[3]++; 
     while (x % 5 == 0) 
           x /= 5, p[5]++; 
     x = k + 1; 
     while (x % 2 == 0) 
           x /= 2, p[2]--; 
     while (x % 3 == 0) 
           x /= 3, p[3]--; 
     while (x % 5 == 0) 
           x /= 5, p[5]--; 
     if (d == 2) 
        count += (p[2] >= 1); 
     if (d == 3) 
        count += (p[3] >= 1); 
     if (d == 4) 
        count += (p[2] >= 2); 
     if (d == 5) 
        count += (p[5] >= 1); 
     if (d == 6) 
        count += (p[2] >= 1 && p[3] >= 1); 
} 
int main() 
{ 
    freopen("pascal.in", "r", stdin);
    freopen("pascal.out", "w", stdout);
    scanf("%d%d", &n, &d);
    for (k=0; k < (n+1)/2-1; k++)
        copy_paste();
    count*=2; 
    if (n % 2 == 0) 
       copy_paste(); 
    printf("%d\n", count); 
    return 0; 
}