Pagini recente » Istoria paginii utilizator/johngiumanca | Istoria paginii runda/avram_simulare_2/clasament | Diferente pentru utilizator/robybrasov intre reviziile 57 si 56 | Cod sursa (job #2553587) | Cod sursa (job #1736466)
#include <fstream>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;
#define llu long long unsigned
#define ll long long
#define pb push_back
#define mp make_pair
string problemName = "pascal";
string inFile = problemName+".in";
string outFile = problemName+".out";
ifstream fin(inFile.c_str());
ofstream fout(outFile.c_str());
int need[6], have[6];
int main(){
int r,d,i,x,d2,d3,d5;
fin>>r>>d;
if(r == 0 || r == 1){
fout<<0;
return 0;
}
while(d%2 == 0){
need[2]++;
d /= 2;
}
while(d%3 == 0){
need[3]++;
d /= 3;
}
while(d%5 == 0){
need[5]++;
d /= 5;
}
int limit = r/2;
int ans = 0;
for(i = 1;i <= limit;i++){
x = r-i+1;
while(x%2 == 0){
have[2]++;
x /= 2;
}
while(x%3 == 0){
have[3]++;
x /= 3;
}
while(x%5 == 0){
have[5]++;
x /= 5;
}
x = i;
while(x%2 == 0){
have[2]--;
x /= 2;
}
while(x%3 == 0){
have[3]--;
x /= 3;
}
while(x%5 == 0){
have[5]--;
x /= 5;
}
if(have[2] >= need[2] && have[3] >= need[3] && have[5] >= need[5]){
ans += 2;
if(i == limit && r%2 == 0){
ans--;
}
}
}
fout<<ans;
return 0;
}