Pagini recente » Cod sursa (job #2553354) | Cod sursa (job #443061) | Cod sursa (job #475117) | Cod sursa (job #780642) | Cod sursa (job #2115611)
#include <bits/stdc++.h>
#define MAXN 5000000
int two[1 + MAXN], three[1 + MAXN], five[1 + MAXN];
int main(){
FILE*fi,*fo;
fi = fopen("pascal.in","r");
fo = fopen("pascal.out","w");
int r, d;
fscanf(fi,"%d%d", &r, &d);
for(int i = 1; i <= r; i++){
int x = i;
two[i] = two[i - 1];
while(x % 2 == 0){
two[i]++;
x /= 2;
}
three[i] = three[i - 1];
while(x % 3 == 0){
three[i]++;
x /= 3;
}
five[i] = five[i - 1];
while(i % 5 == 0){
five[i]++;
i /= 5;
}
}
int con = 0;
for(int i = 0; i <= r; i++){
int a = two[r] - two[i] - two[r - i];
int b = three[r] - three[i] - three[r - i];
int c = five[r] - five[i] - five[r - i];
if(d == 2 && a >= 1) con++;
else if(d == 3 && b >= 1) con++;
else if(d == 4 && a >= 2) con++;
else if(d == 5 && c >= 1) con++;
else if(d == 6 && a >= 1 && b >= 1) con++;
}
fprintf(fo,"%d", con);
fclose(fi);
fclose(fo);
return 0;
}