Pagini recente » Monitorul de evaluare | Istoria paginii runda/9neplace_5 | Rating Croitorescu Madalin (WinnerM) | Atasamentele paginii Clasament oni2011-uh | Cod sursa (job #2281043)
#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 *= p;
}
}
if(D == 3 || D == 6){
int p = 3;
while(p <= i){
trei[i] += i / p;
p *= p;
}
}
if(D == 5){
int p = 5;
while(p <= i){
cinci[i] += i / p;
p *= p;
}
}
}
int k = 0;
for(int j = 0; j < R; ++j){
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;
}
}
out << k;
return 0;
}