Mai intai trebuie sa te autentifici.
Cod sursa(job #289839)
Utilizator | Data | 27 martie 2009 08:18:22 | |
---|---|---|---|
Problema | Pascal | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.47 kb |
//#include<algorithm>
//using namespace std;
#include<stdio.h>
int r,d,sol;
int fact(int x,int y){
int exp;
for(exp=0; x; exp+=x/=y);
return exp;}
void solve(){
int i,s0,s1,x02,x12,x22,x03,x13,x23;
scanf("%d%d",&r,&d);
if(d==6){
if(r%2==0){
for(i=0; i<r/2; ++i){
x02=fact(r,2);
x12=fact(i,2);
x22=fact(r-i,2);
x03=fact(r,3);
x13=fact(i,3);
x23=fact(r-i,3);}
s0=x02-x12-x22;
s1=x03-x13-x23;
if((s0>=0&&s1>0)||(s0>0&&s1>=0))
sol+=2;
x02=fact(r,2);
x12=fact(r/2,2);
x22=fact(r/2+1,2);
x03=fact(r,3);
x13=fact(r/2,3);
x23=fact(r/2+1,3);
s0=x02-x12-x22;
s1=x03-x13-x23;
if((s0>=0&&s1>0)||(s0>0&&s1>=0))
++sol;}
else{
for(i=0; i<=r/2; ++i){
x02=fact(r,2);
x12=fact(i,2);
x22=fact(r-i,2);
x03=fact(r,3);
x13=fact(i,3);
x23=fact(r-i,3);}
s0=x02-x12-x22;
s1=x03-x13-x23;
if((s0>=0&&s1>0)||(s0>0&&s1>=0))
sol+=2;}}
printf("%d",sol);}
int main(){
freopen("pascal.in","r",stdin);
freopen("pascal.out","w",stdout);
solve();
return 0;}