Cod sursa(job #1358730)

Utilizator vergilius_beberindeie virgil vergilius_be Data 24 februarie 2015 19:26:29
Problema Progresie Scor 0
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.82 kb
#include<fstream>
#include<cmath>
using namespace std;

int main()
{
    long long i,j,n,t,r,u,t1,k;
    double h;
    bool ok;
    ifstream f("progresie.in");
    ofstream g("progresie.out");
    f>>t;
    for(i=1;i<=t;i++)
    {
        f>>n>>r;
        for(k=1;k<=1000000;k++)
        {
        for(j=k*(k-1)+1;j<=k*k;j++)
        {
                t1=j;
                ok=true;
                for(u=1;u<n;u++)
                {
                    t1=t1+r;
                    h=sqrt(t1);
                    if (h!=trunc(h))
                       if((t1<(trunc(h)+1)*trunc(h)+1 || t1>(trunc(h)+1)*(trunc(h)+1))) {ok=false; break;}
                }
                if(ok==true) break;
        }
      if(ok==true)  {g<<j<<'\n'; break;}
    }
    }
    f.close();
    g.close();
    return 0;
}