Pagini recente » Cod sursa (job #1122766) | Cod sursa (job #1273460) | Cod sursa (job #1350656) | Cod sursa (job #3016) | Cod sursa (job #1245302)
#include <bits/stdc++.h>
using namespace std;
int solve(int N, int R) {
for (int start = 1;; ++start) {
bool isGood = true;
for (int i = 0; i < N; ++i) {
int number = start + i * R;
int sq = (int)ceil(sqrt((double)number));
int upLimit = sq * sq;
int downLimit = upLimit - sq;
if ((number < downLimit + 1) || (number > upLimit)) {
isGood = false;
break;
}
}
if (isGood) {
return start;
}
}
}
int main() {
ifstream in("progresie.in");
ofstream out("progresie.out");
int T = 0;
in >> T;
for (int i = 0; i < T; ++i) {
int N, R;
in >> N >> R;
out << solve(N, R) << "\n";
}
in.close();
out.close();
return 0;
}