Cod sursa(job #2916552)

Utilizator BlaugranasEnal Gemaledin Blaugranas Data 30 iulie 2022 14:45:08
Problema Progresie Scor 0
Compilator cpp-64 Status done
Runda Arhiva ICPC Marime 0.48 kb
#include<bits/stdc++.h>
using namespace std;
ifstream F("progresie.in");
ofstream G("progresie.out");
int t;
long long n,r,x,l,j,k,y,i,e;
bool o;
int main()
{
    for(F>>t;t;--t)
        for(F>>n>>r,o=1,x=r*(n-1)+1,i=1;o&&i<=x;++i) {
            for(j=i*i-i+1,k=0;k<n;++k) {
                y=j+k*r,l=sqrt(y);
                if(y!=l*l&&y<=l*(l+1))
                    break;
            }
            if(k==n)
                G<<j<<'\n',o=0;
        }
    return 0;
}