Pagini recente » Cod sursa (job #2586912) | Cod sursa (job #30992) | Cod sursa (job #1178853) | Cod sursa (job #1279568) | Cod sursa (job #3148946)
#include <fstream>
using namespace std;
ifstream fin("pascal.in");
ofstream fout("pascal.out");
int R,D, sol, main_two, main_five, two, five, main_three, three, d2, d3, d5;
int get_pow(long long N, long long P) {
int nr = 0, cnt = 0;
while(P <= N) {
cnt += 1;
nr += N / P;
P = P * P;
if (cnt > 3)
break;
}
return nr;
}
int main() {
// your code goes here
fin >> R >> D;
main_two = get_pow(R, 2);
main_five = get_pow(R, 5);
main_three = get_pow(R, 3);
d2 = 0;
if (D % 2 == 0)
d2 ++;
if (D % 4 == 0)
d2 ++;
if (D % 3 == 0)
d3 ++;
if (D % 5 == 0)
d5 ++;
for (int j = 0; j<= R; j++) {
two = main_two - get_pow(j, 2) - get_pow(R - j, 2);
five = main_five - get_pow(j, 5) - get_pow(R - j, 5);
three = main_three - get_pow(j, 3) - get_pow(R - j, 3);
if (two >= d2 && five >= d5 && three >= d3)
sol++;
}
fout << sol;
return 0;
}