Cod sursa(job #2918457)

Utilizator BlaugranasEnal Gemaledin Blaugranas Data 11 august 2022 15:52:46
Problema Progresie Scor 100
Compilator cpp-64 Status done
Runda Arhiva ICPC Marime 0.6 kb
#include<bits/stdc++.h>
using namespace std;
ifstream F("progresie.in");
ofstream G("progresie.out");
long long t,n,r;
void S()
{
    long long k,i,j,x,l;
    for(k=1;;++k) {
        for(i=k*(k-1)+1;i<=k*k;) {
            for(j=1;j<n;++j) {
                x=i+j*r,l=sqrt(x);
                if(x==l*l||x>(l+1)*l)
                    continue;
                i+=(l+1)*l+1-x;
                break;
            }
            if(j==n) {
                G<<i<<'\n';
                return;
            }
        }
    }
}
int main()
{
    for(F>>t;t;F>>n>>r,S(),--t);
    return 0;
}