Cod sursa(job #3310045)

Utilizator popescu_georgePopescu George popescu_george Data 11 septembrie 2025 15:08:04
Problema Progresie Scor 0
Compilator cpp-64 Status done
Runda Arhiva ICPC Marime 0.62 kb
#include<fstream>
#include<cmath>
using namespace std;
ifstream cin("progresie.in");
ofstream cout("progresie.out");
int main()
{
    short t;
    for(cin>>t;t--;) {
        short n;
        int r;
        cin>>n>>r;
        bool o=1;
        for(int i=1;o;) {
            int j=1;
            long long v=1LL*i*(i-1)+1;
            for(;j<n;++j) {
                long long l=v+1LL*j*r,b=sqrt(l-1)+1,x=1LL*b*(b-1)+1;
                if(l<x) {
                    v+=x-l;
                    break;
                }
            }
            j==n?cout<<v<<'\n',o=0:++i;
        }
    }
    return 0;
}