Cod sursa(job #2918466)

Utilizator BlaugranasEnal Gemaledin Blaugranas Data 11 august 2022 16:10:55
Problema Progresie Scor 100
Compilator cpp-64 Status done
Runda Arhiva ICPC Marime 0.62 kb
#include<bits/stdc++.h>
using namespace std;
ifstream F("progresie.in");
ofstream G("progresie.out");
#define L long long
int t;
void T()
{
    L n,r,i,v,l,b,x,y,e,j;
    bool o;
    F>>n>>r;
    for(i=1;;++i) {
        for(v=i*(i-1)+1,e=i-1,o=1,j=1;j<n&&o;++j) {
            l=v+j*r,b=sqrt(l-1)+1,x=b*(b-1)+1,y=b*b;
            if(l<x)
                v+=x-l,e-=x-l;
            else
                e=min(e,y-l);
            if(l+e<x)
                o=0;
        }
        if(o) {
            G<<v<<'\n';
            return;
        }
    }
}
int main()
{
    for(F>>t;t;T(),--t);
    return 0;
}