Pagini recente » Cod sursa (job #1520869) | Cod sursa (job #166528) | Cod sursa (job #942018) | Cod sursa (job #2868985) | Cod sursa (job #2281124)
#include <iostream>
#include <fstream>
#include <cmath>
int main()
{
std::ifstream in("pascal.in");
std::ofstream out("pascal.out");
//citire
long long R;
int D;
in >> R >> D;
int doi[R + 1] = {}, trei[R + 1] = {}, cinci[R + 1] = {};
for(int i = 2; i <= R; ++i){
if(D == 2 || D == 4 || D == 6){
int p = 2;
while(p <= i){
doi[i] += i / p;
p *= 2;
}
}
if(D == 3 || D == 6){
int p = 3;
while(p <= i){
trei[i] += i / p;
p *= 3;
}
}
if(D == 5){
int p = 5;
while(p <= i){
cinci[i] += i / p;
p *= 5;
}
}
}
int k = 0;
if(D == 2){
for(int j = 0; j < R / 2; ++j){
int comb2 = std::abs(doi[R] - doi[R - j] - doi[j]);
if(comb2 > 0) k += 2;
}
}
else if(D == 4){
for(int j = 0; j < R / 2; ++j){
int comb2 = std::abs(doi[R] - doi[R - j] - doi[j]);
if(comb2 > 1) k += 2;
}
}
else if(D == 3){
for(int j = 0; j < R / 2; ++j){
int comb3 = std::abs(trei[R] - trei[R - j] - trei[j]);
if(comb3 > 0) k += 2;
}
}
else if(D == 6){
for(int j = 0; j < R / 2; ++j){
int comb3 = std::abs(trei[R] - trei[R - j] - trei[j]);
int comb2 = std::abs(doi[R] - doi[R - j] - doi[j]);
if(comb3 > 0 && comb2 > 0) k += 2;
}
}
else{
for(int j = 0; j < R / 2; ++j){
int comb5 = std::abs(cinci[R] - cinci[R - j] - cinci[j]);
if(comb5 > 0) k += 2;
}
}
int j = R / 2;
int init_k = k;
if(D == 2){
int comb2 = std::abs(doi[R] - doi[R - j] - doi[j]);
if(comb2 > 0) ++k;
}
else if(D == 4){
int comb2 = std::abs(doi[R] - doi[R - j] - doi[j]);
if(comb2 > 1) ++k;
}
else if(D == 3){
int comb3 = std::abs(trei[R] - trei[R - j] - trei[j]);
if(comb3 > 0) ++k;
}
else if(D == 6){
int comb3 = std::abs(trei[R] - trei[R - j] - trei[j]);
int comb2 = std::abs(doi[R] - doi[R - j] - doi[j]);
if(comb3 > 0 && comb2 > 0) ++k;
}
else{
int comb5 = std::abs(cinci[R] - cinci[R - j] - cinci[j]);
if(comb5 > 0) ++k;
}
if(k > init_k && R % 2 == 1){
++k;
}
out << k;
return 0;
}