Cod sursa(job #2918460)

Utilizator BlaugranasEnal Gemaledin Blaugranas Data 11 august 2022 15:57:04
Problema Progresie Scor 0
Compilator cpp-64 Status done
Runda Arhiva ICPC Marime 0.53 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,y;
    for(y=r*(n-1)+1,i=1;i<=y*(y-1)+1;) {
        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;
}