Pagini recente » Cod sursa (job #2462277) | Cod sursa (job #2254202) | Cod sursa (job #1339128) | Cod sursa (job #3001017) | Cod sursa (job #1207603)
#include <fstream>
#define max_c 5000005
using namespace std;
int Fact[3][max_c],Exp[3],Nr[3],Act[3];
int r,d;
int ok,rez,ind,p;
int i,j;
int main(){
ifstream f("pascal.in");
ofstream g("pascal.out");
f>>r>>d;
if( d==2 )
Nr[0]=1;
if( d==3 )
Nr[1]=1;
if( d==4 )
Nr[0]=2;
if( d==5 )
Nr[2]=1;
if( d==6 )
Nr[0]=Nr[1]=1;
Exp[0]=2;
Exp[1]=3;
Exp[2]=5;
for( ind=0; ind<3; ++ind ){
for( p=Exp[ind]; p<=r; p*=Exp[ind] ){
for( i=p; i<=r; i+=p )
Fact[ind][i]++;
}
}
rez=0;
for( i=1; i<r; ++i ){
ok=1;
for( j=0; j<3; ++j ){
Act[j]-=Fact[j][i];
Act[j]+=Fact[j][r-i+1];
if( Act[j]<Nr[j] )
ok=0;
}
rez+=ok;
}
g<<rez;
return 0;
}