Pagini recente » Cod sursa (job #1272466) | Cod sursa (job #2059670) | Cod sursa (job #1899122) | Cod sursa (job #3192744) | Cod sursa (job #2981124)
#include <bits/stdc++.h>
#include <fstream>
#include <limits.h>
#define INF (1e9) + 7;
using namespace std;
ifstream f("progresie.in");
ofstream g("progresie.out");
int fact[1000001], lastFact = 1;
int main()
{
int64_t t;
f >> t;
for (int z = 1; z <= t; z++)
{
int64_t n, r;
f >> n >> r;
int64_t eStart = (n - 1) * r + 1;
int64_t cn = n;
//eStart * (eStart - 1) + 1
//eStart * eStart
int64_t c = eStart * (eStart - 1) + 1;
while (c <= eStart * eStart)
{
c += r;
cn--;
}
if (cn==0)
g << eStart * (eStart - 1) + 1;
else g << -1;
g<<endl;
}
return 0;
}