Cod sursa(job #2918438)

Utilizator BlaugranasEnal Gemaledin Blaugranas Data 11 august 2022 15:25:17
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");
int t;
long long n,r,l,j,k,i,y;
bool o;
int main()
{
    for(F>>t;t;--t)
        for(F>>n>>r,o=1,i=1;o;++i)
            for(j=i*(i-1)+1;j<=i*i&&o;j+=l*(l+1)+1-y) {
                for(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;
}