Cod sursa(job #3310040)

Utilizator popescu_georgePopescu George popescu_george Data 11 septembrie 2025 14:14:35
Problema Progresie Scor 100
Compilator cpp-64 Status done
Runda Arhiva ICPC Marime 0.74 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;
        long long k=1LL*(r*n-r+1)*(r*n-r+1)-r*n+r;
        bool f=1;
        for(long long i=1;i<k&&f;) {
            long long x=0,y=i+1LL*r*n-r;
            for(long long l=i;l<=y&&!x;l+=r) {
                int q=(int)sqrt(l);
                if(1LL*q*q!=l&&1LL*(q+1)*(q+1)-q>l)
                    x=1LL*(q+1)*(q+1)-q-l;
            }
            if(!x)
                cout<<i<<'\n',f=0;
            else
                i+=x;
        }
        if(f)
            cout<<k<<'\n';
    }
    return 0;
}